English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

We use Gnu 2.1.73 and SciTE

fprintf('\nThis program solves the equation ax^2+bx+c=0 for x.\n\n');
a = input('Enter the coefficient a: ');
b = input('Enter the coefficient b: ');
c = input('Enter the coefficient c: ');

if(a==b==c==0)
fprintf('all possible solutions\n');
elseif(a==b==0)
fprintf('no possible solutions\n');
elseif(b^2-4*a*c < 0)
fprintf('no real solutions\n');
elseif(b^2-4*a*c ==0)
x = -b/(2*a)
fprintf('%3.2f.\n', x);
elseif(b^2-4*a*c > 0)
x1 = (-b+(((b^2)-4*a*c)^(1/2)))/(2*a)
x2 = (-b-(((b^2-4*a*c)^(1/2))))/(2*a)
fprintf('The quadratic equation has two solutions:');
disp([x1 x2]);
end;

2006-09-04 17:39:28 · 4 answers · asked by Anonymous in Science & Mathematics Engineering

fprintf('\nThis program solves the equation ax^2+bx+c=0 for x.\n\n');
a = input('Enter the coefficient a: ');
b = input('Enter the coefficient b: ');
c = input('Enter the coefficient c: ');
(d = b^2+4*a*c);
if (a==b==c==0)
fprintf('all possible solutions\n');
elseif (a==b==0)
fprintf('no possible solutions\n');
elseif (d < 0)
fprintf('no real solutions\n');
elseif (d==0)
x = -b/(2*a)
fprintf('The quadratic equation has one solution:');
disp([x])
else (d > 0)
(x1 = ((-b+d^1/2)/(2*a)));
(x2 = ((-b-d^1/2)/(2*a)));
fprintf('The quadratic equation has two solutions:');
disp([x1 x2]);
endif;

if i enter 1,0,1or any other combo of numbers is say "all possible solutions"
Also I believe if a=b=c=0 is not the same as a=b=0 because what if it is 0,0,1.

2006-09-04 21:29:18 · update #1

4 answers

Hey,

I have a few suggestions. I am not familiar to SciTE, but it resembles Matlab which I've worked with.

Try setting a variable for your equation for the elseif comparisons.

ie. d = ax^2+bx+c

Then use elseif(d < 0);

You could also use if(d==0)
This would correct any issues dealing with the variables. In Matlab they have this horrible "dot notation". Where when a defined variable is altered you need to add a period/dot before it. Make sure there isn't anything like that required.

Also make sure you are using your if arguments correctly. Does the syntax support "and/or" arguments such as && / || ?

2006-09-04 17:50:02 · answer #1 · answered by dreft 2 · 0 0

I don't know what is "Gnu 2.1.73 and SciTE" but you can check these items:
1- when (a=b=c=0) is true, then (a=b=0) will be true too. hence you will have both "all possible solutions" and "'no possible solutions" in output.
2- can you use an empty line?(as you have used in 5th line)
3- is it possible to use more than one "elseif" for each "if"?
4- don't you need any other command when you use "if"? (for instance an "endif" command)

2006-09-04 21:18:56 · answer #2 · answered by Hossein M 1 · 0 0

Try again.

2006-09-06 11:49:51 · answer #3 · answered by Anonymous · 0 0

...dunno what Gnu 1.1.73 and SciTE are, but your solution equations seem to be unfinished.

2006-09-04 17:58:24 · answer #4 · answered by Helmut 7 · 0 0

fedest.com, questions and answers