Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe04.iad.POSTED!7564ea0f!not-for-mail
From: "Nasser M. Abbasi" <nma@12000.org>
Newsgroups: comp.soft-sys.matlab
References: <hcpse6$7ac$1@fred.mathworks.com>
Subject: Re: how to solve a set of nonlinear equation systems with changing coefficients
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3598
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
X-RFC2646: Format=Flowed; Original
X-EsetId: 321EA926BF2033396658
X-EsetScannerBuild: 5963
Message-ID: <gI0Im.789$fE2.146@newsfe04.iad>
NNTP-Posting-Host: ncdeodfefpjopplmihjclpliaacepnnh
X-Complaints-To: abuse@charter.net
X-Trace: ifnckfofmjglplgfadefjppgkgeilljaadigcajjknmidkfincdeodfefpjopplmmgdmmdanmgdmojgmdpnkapfhjflphnecildolkkeocphpjlefakekmgeaglnhickfengolcelnpbekad
NNTP-Posting-Date: Tue, 03 Nov 2009 20:50:20 UTC
Date: Tue, 3 Nov 2009 14:50:19 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:582164



"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