From: Jake on
help me implement bisection method

function bisect(n)

syms x;

f = 4 * x + 2;

n = int32(n);

double a;
double b;
double m;

double err;

err = 1;
b=5;
a=-5;

while(b-a > err ){
m = (a+b)/2 ;
if( subf(f,a) * subf(f,m) > 0){
m=a;
}

else{
m=b;
}

}
end


The error that iam getting is

Error: File: bisect.m Line: 20 Column: 4
The expression to the left of the equals sign is not a valid target for an assignment.
From: Matt J on
"Jake " <nathan.a2000(a)googlemail.com> wrote in message <hpslmr$cto$1(a)fred.mathworks.com>...

> The error that iam getting is
>
> Error: File: bisect.m Line: 20 Column: 4
> The expression to the left of the equals sign is not a valid target for an assignment.
=============

Then why don't you show us the code you are actually running, instead of this MATLAB/C code hybrid which would have no hope of running? Preferably also, you would indicate line 20 for us, which is where the error is being reported.
From: Jake on
Well the one that i posted is the actual code that iam getting an error.

Line 20 is

m = (a+b)/2 ;

please help
From: Walter Roberson on
Jake wrote:
> Well the one that i posted is the actual code that iam getting an error.
> Line 20 is
>
> m = (a+b)/2 ;
>
> please help

{ } are not flow groupers in Matlab. The { at the end of your if
statement is causing a problem.

Your program is not written in Matlab. In Matlab, the statement

double a;

means to call the routine double() and pass in the character string 'a',
get the numeric value of that 'a' as a double precision number and
return that out from the double() call. The semi-colon following then
instructs Matlab to discard the value; without the semi-colon, Matlab
would display the result of the call double('a') .

I'm not going to bother to catalog all of the problems in your program,
because I think you are trolling.
From: Jake on
Okay i resolved the other errors but now iam getting a new one

if( subf(f,a) * subf(f,m) > 0)

Why is this statement wrong?
 |  Next  |  Last
Pages: 1 2
Prev: creating symbolic variables
Next: binary-grayscale