MATLAB Answers

Semi-Colon not supressing output

3 views (last 30 days)
Justin on 23 Feb 2015
Edited: John D'Errico on 23 Feb 2015
I was wondering if someone would be able to help me. I wrote this code for the bisection method:
a = 0;
b = 1;
accuracy = 0.00000001;
if RRE(a,Z,K) == 0; %Checks if lower bound is the root. a is already the root.
Ps = a;
elseif RRE(b,Z,K) == 0; %Checks if the upper bound is the root b is already the root.
Ps = b;
elseif RRE(a,Z,K)*RRE(b,Z,K) > 0;
error('RRE(a) and RRE(b) do not have opposite signs. Try a different bound or check if your Z and K values are correct.'); %custom error code
while (b-a > accuracy || (abs(RRE(a,Z,K)) > accuracy && abs(RRE(b,Z,K)) > accuracy)); %repeat the bisection method until both f(a) and f(b) are less than 'accuracy' or until the difference between a and b are less than 'accuracy'
c = (a+b)/2; %Midpoint Method
%c = a - (((b-a)*RRE(a,Z,K))/(RRE(b,Z,K)-RRE(a,Z,K))); %False-Position Method
if RRE(c,Z,K) == 0;
Ps = c;
elseif RRE(a,Z,K)*RRE(c,Z,K) < 0; %If f(a)*f(c) is a negative # then make the next range from [a c]. To do this you make c the new b
b = c;
a = c; %If f(a)*f(c) is a posituve # then make the next range from [c b]. To do this you make c the new a value
if RRE(c,Z,K) == 0;
Ps = c;
elseif RRE(a,Z,K)<RRE(b,Z,K); %Choose the x-value that brings f(psi) closest to 0.
Ps = a;
Ps = b;
However, when I run this code my function RRE is calculating a value AND printing it out on the command window. I've checked all my semi-colons and all the lines are supressed. I'm stuck. I have no idea why my function RRE is printing to the command window.
Please help.
John D'Errico
John D'Errico on 23 Feb 2015
You did not give us the function RRE. The problem is most likely in there.
By the way, I want to really compliment you on the use of internal comments. They make your code far more debuggable. So a good job there. I also like that you have error checking in the code.
You might consider using more expressive variable names though. They also make code more readable, more debuggable.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!