I don't get the desired output when running the following code. The output generated is shown in the image.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
The task is to generate the roots of a quadratic equation and the value of the variables are entered by the user. I have used the following code:
%%findingRoots.m
border=['*************************************************'];
intro=['Quadratic Solver for ax^2+bx+c=0'];
disp(border);
disp(intro);
a=input('Please enter a: ');
b=input('Please enter b: ');
c=input('Please enter c: ');
z1=(-b+(b^2-(4*a*c))^0.5)/(2*a);
z2=(-b-(b^2-(4*a*c))^0.5)/(2*a);
root=['The roots are: '];
root1=['z1 = ', z1];
root2=['z2 = ', z2];
disp(root);
disp(root1);
disp(root2);
and I get the response as shown in the image.
0 Kommentare
Antworten (1)
Zoltán Csáti
am 27 Okt. 2014
I do not see the image (perhaps you did not attach it), but the error in your code is the following. You want to display a string so first you must convert z1 and z2 to strings, like this:
root1=['z1 = ', num2str(z1)];
root2=['z2 = ', num2str(z2)];
Then it will work.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!