From: deepak on
Hi,

i am trying to solve system of nonlinear equations using fsolve and myfun is :

function F=myfunt(y)
x1=10;
y1=5*sind(x1);

theta1=90+atand(-1/5*cosd(x1));
x2=x1-2*sind(theta1);
y2=y1+2*cosd(theta1);

F=[y(1)-x2+10*cosd(y(2))-2*sind(90+atand(-1/5*cosd(y(1)))); 5*sind(y(1))-y2+10*sind(y(2))+2*cosd(90+atand(-1/5*cosd(y(1))))];

here i have to provide x1 for each time i want to solve it .but i want function myfunt to take value of x1 from main program so that i can solve this system of NLE for different value of x1.

please help.

thanx.
From: Sean on
"deepak " <dkjknobel(a)rediff.com> wrote in message <ht5l44$it4$1(a)fred.mathworks.com>...
> Hi,
>
> i am trying to solve system of nonlinear equations using fsolve and myfun is :
>
> function F=myfunt(y)
> x1=10;
> y1=5*sind(x1);
>
> theta1=90+atand(-1/5*cosd(x1));
> x2=x1-2*sind(theta1);
> y2=y1+2*cosd(theta1);
>
> F=[y(1)-x2+10*cosd(y(2))-2*sind(90+atand(-1/5*cosd(y(1)))); 5*sind(y(1))-y2+10*sind(y(2))+2*cosd(90+atand(-1/5*cosd(y(1))))];
>
> here i have to provide x1 for each time i want to solve it .but i want function myfunt to take value of x1 from main program so that i can solve this system of NLE for different value of x1.
>
> please help.
>
> thanx.

One way: make an anonymous function that does the work for you
>>myfun_withx1 = @(y) myfun(y,x1)
just make sure you redefine the handle every time you change x1.
From: deepak on

can you please elaborate the procedure for doing that.

thnx
From: Sean on
"deepak " <dkjknobel(a)rediff.com> wrote in message <ht6aas$42t$1(a)fred.mathworks.com>...
>
> can you please elaborate the procedure for doing that.


x1 = [10, 42, pi, 19, -17, e^pi*i];
Results = cell(size(x1));
for ii = 1:numel(x1)
myfun_now = @(y)my_funt(y,x1(ii)); %Change your myfunt to accept x1 as input
results(ii) = fsolve(@myfun_now);
end