I don't get the desired output when running the following code. The output generated is shown in the image.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Zoltán Csáti
2014-10-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!