Question: THIS IS A MATLAB QUESTION. The statement given below calculates the roots of 4x^3-12x^2+x-3. Use the if construct to determine if each root is the
THIS IS A MATLAB QUESTION.
The statement given below calculates the roots of 4x^3-12x^2+x-3.
Use the "if construct" to determine if each root is the real or complex. Use the MATLAB
command "isreal" to check each of the 3 roots, one root at a time. "isreal" returns
a 1 if real, a zero if not. Example: isreal(4)=1 isreal(4+2i)=0. [6]
As part of the if statement use fprintf to display a message like "Root number 2 is
complex". Note that "2" is a counter in your loop - not the root value. [2]
Put your "if" construct in a "for" loop so you can check all of the roots [2].
p=[4 -12 1 -3]; r=roots(p) % start your "for" loop here for i=1:length(r) if isreal r(i) fprintf(' The root number %g is real ',r(i)) else fprintf(' The root number %g is complex ',r(i)) end end fprintf(' ');
I believe it's all correct , except I'm using isreal incorrect. Could someone help, so I can finish this code. Thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
