From: deepak on
I want to solve a set of nonlinear equation where there is an if else contion on one of variable .

when i tried using if else condition in definition of myfun it is returning error.

Here is the myfun

function F=myfunt(x)
x1=12;
y1=2*tand(10);
w=15;
x2=x(1);
y2=x(2);
F=[x2-x1-w*cos(theta);y2-y1-w*sin(theta);if x2>10,y2 =(x2-10)*tand(10),else y2=0, end];

can somebody please tell me how to incorporate these in fsolve.

Thanks & regards

deepak
From: Alan Weiss on
On 7/14/2010 6:55 AM, deepak wrote:
> I want to solve a set of nonlinear equation where there is an if else
> contion on one of variable .
>
> when i tried using if else condition in definition of myfun it is
> returning error.
>
> Here is the myfun
>
> function F=myfunt(x)
> x1=12;
> y1=2*tand(10);
> w=15;
> x2=x(1);
> y2=x(2);
> F=[x2-x1-w*cos(theta);y2-y1-w*sin(theta);if x2>10,y2
> =(x2-10)*tand(10),else y2=0, end];
>
> can somebody please tell me how to incorporate these in fsolve.
>
> Thanks & regards
>
> deepak

See the documentation for "if":
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html

You also need to define your variable "theta". Did you mean x2?

Alan Weiss
MATLAB mathematical toolbox documentation
From: deepak on
Thnx alan,

ya i forgot to define theta actually it's

x(3)=theta.

Still i'm unable to understand the how to use if else condition.
I'm a naive for matlab . can you please exaplain it by showing some example or by solving above system of non linear equation.

Thanks and regards

Deepak
From: us on
"deepak " <dkjknobel(a)rediff.com> wrote in message <i1kacs$a82$1(a)fred.mathworks.com>...
> Thnx alan,
>
> ya i forgot to define theta actually it's
>
> x(3)=theta.
>
> Still i'm unable to understand the how to use if else condition.
> I'm a naive for matlab . can you please exaplain it by showing some example or by solving above system of non linear equation.
>
> Thanks and regards
>
> Deepak

well...
it most certainly would be intelligent to show the actual ERROR message before CSSMers propel themselves into outer space with useless philosophical floods of words...
THINK - then POST...

us
From: Alan Weiss on
On 7/14/2010 8:26 AM, deepak wrote:
> Thnx alan,
>
> ya i forgot to define theta actually it's
>
> x(3)=theta.
>
> Still i'm unable to understand the how to use if else condition.
> I'm a naive for matlab . can you please exaplain it by showing some
> example or by solving above system of non linear equation.
>
> Thanks and regards
>
> Deepak

Well, just as an example:
function F=myfunt(x)
x1=12;
y1=2*tand(10);
w=15;
x2=x(1);
theta = x(3);
if x2 > 10
y2 = (x2-10)*tand(10);
else
y2 = 0;
end
F=[x2-x1-w*cos(theta);y2-y1-w*sin(theta);cos(y2)+3;17-exp(-x2)];

Alan Weiss
MATLAB mathematical toolbox documentation