Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
using if else condition in fsolve

Subject: using if else condition in fsolve

From: deepak

Date: 14 Jul, 2010 10:55:09

Message: 1 of 8

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

Subject: using if else condition in fsolve

From: Alan Weiss

Date: 14 Jul, 2010 11:57:04

Message: 2 of 8

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

Subject: using if else condition in fsolve

From: deepak

Date: 14 Jul, 2010 12:26:04

Message: 3 of 8

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

Subject: using if else condition in fsolve

From: us

Date: 14 Jul, 2010 12:46:04

Message: 4 of 8

"deepak " <dkjknobel@rediff.com> wrote in message <i1kacs$a82$1@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

Subject: Reply for u mr. US

From: deepak

Date: 14 Jul, 2010 12:56:13

Message: 5 of 8

Mr. US

i am not asking you to answer so why don't you keep you big mouth shut.

Subject: Sorry Mr. Us

From: deepak

Date: 14 Jul, 2010 13:03:07

Message: 6 of 8

I'm really sorry for my earlier remarks.
It was a fool of me to make such a nasty comment

Kindly forgive me.

Regards

Subject: Sorry Mr. Us

From: us

Date: 14 Jul, 2010 13:28:27

Message: 7 of 8

"deepak " <dkjknobel@rediff.com> wrote in message <i1kcib$1gh$1@fred.mathworks.com>...
> I'm really sorry for my earlier remarks.
> It was a fool of me to make such a nasty comment
>
> Kindly forgive me.
>
> Regards

well...
don't worry(!)...
here at CSSM CSSMers can take it...

:-)
us

Subject: using if else condition in fsolve

From: Alan Weiss

Date: 14 Jul, 2010 15:59:13

Message: 8 of 8

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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us