I don't get the desired output when running the following code. The output generated is shown in the image.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Zoltán Csáti
el 27 de Oct. de 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 comentarios
Ver también
Categorías
Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!