|
"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
|