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 %26lt; 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 %26gt; 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;
I am working on this problem for my one of my classes and can't seem to get it to work. Any suggestions?
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 %26lt; 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 %26amp;%26amp; / || ?
Reply:...dunno what Gnu 1.1.73 and SciTE are, but your solution equations seem to be unfinished.
Reply:Try again.
Reply: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)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment