Thread Subject: how to solve a set of nonlinear equation systems with changing coefficients

Subject: how to solve a set of nonlinear equation systems with changing coefficients

From: Gyusok

Date: 3 Nov, 2009 18:23:02

Message: 1 of 3

Hello,

I have to solve the following problem; I hope that someone can help me.
I would like to solve the function and obtain a vector x = [x(1); x(2)]
for varying values of theta and the vector p =[ p(1); p(2)]

>>
function findphi = findphi(x)
findphi = [cos(theta)*(sin(x(1)) - x(2)*x(1)*cos(x(1))) + ...
          sin(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(1) ;
         -sin(theta) * (sin(x(1)) - x(2) * x(1) * cos(x(1))) + ...
          cos(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(2)];
>>

I could use the 'fsolve' command for one specific case, but I have to do this 77 times for changing values of p and theta.

e.g. if I insert

>>
x0 = [0.7; 1]
x = fsolve('findphi', x0)
>>
The values of the coefficients are not known to the function 'findphi' although present in workspace.
Does anybody know how I can pass these coefficients to my function?

Is there any suitable way for stack processing this?

Thank you for your help-.

Gyusok

Subject: how to solve a set of nonlinear equation systems with changing coefficients

From: Nasser M. Abbasi

Date: 3 Nov, 2009 20:50:19

Message: 2 of 3


"Gyusok " <gyusok@gmail.com> wrote in message
news:hcpse6$7ac$1@fred.mathworks.com...
> Hello,
>
> I have to solve the following problem; I hope that someone can help me.
> I would like to solve the function and obtain a vector x = [x(1); x(2)]
> for varying values of theta and the vector p =[ p(1); p(2)]
>
>>>
> function findphi = findphi(x)
> findphi = [cos(theta)*(sin(x(1)) - x(2)*x(1)*cos(x(1))) + ...
> sin(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(1) ;
> -sin(theta) * (sin(x(1)) - x(2) * x(1) * cos(x(1))) + ...
> cos(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(2)];
>>>
>
> I could use the 'fsolve' command for one specific case, but I have to do
> this 77 times for changing values of p and theta.
>
> e.g. if I insert
>
>>>
> x0 = [0.7; 1]
> x = fsolve('findphi', x0)
>>>
> The values of the coefficients are not known to the function 'findphi'
> although present in workspace.
> Does anybody know how I can pass these coefficients to my function?
>
> Is there any suitable way for stack processing this?
>
> Thank you for your help-.
>
> Gyusok


one way is to use global

FUNCTION
============

function findphi = findphi(x)

global p theta

findphi = [cos(theta)*(sin(x(1)) - x(2)*x(1)*cos(x(1))) + ...
             sin(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(1) ;
             -sin(theta) * (sin(x(1)) - x(2) * x(1) * cos(x(1))) + ...
             cos(theta) * (cos(x(1)) + x(2) * x(1) * cos(x(1))) - p(2)];

WORK SPACE:
============
theta=pi/4; p=[1;2];
global theta p
x0 = [0.7; 1];

fsolve('findphi', x0)


Optimization terminated: first-order optimality is less than options.TolFun.

ans =

    0.7848
    2.5462

--Nasser

Subject: how to solve a set of nonlinear equation systems with changing coefficients

From: Nasser M. Abbasi

Date: 3 Nov, 2009 20:52:44

Message: 3 of 3


"Nasser M. Abbasi" <nma@12000.org> wrote in message
news:gI0Im.789$fE2.146@newsfe04.iad...

> theta=pi/4; p=[1;2];
> global theta p

Better to reverse the order above

global theta p
theta=pi/4; p=[1;2];

--Nasser

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
nonlinear Gyusok 3 Nov, 2009 13:24:03
varying coeffic... Gyusok 3 Nov, 2009 13:24:03
pass coefficien... Gyusok 3 Nov, 2009 13:24:03
nonlinear equat... Gyusok 3 Nov, 2009 13:24:03
rssFeed for this Thread

Contact us at files@mathworks.com