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:
calling value of variable from main program into myfun while using fsolve

Subject: calling value of variable from main program into myfun while using fsolve

From: deepak

Date: 21 May, 2010 09:52:04

Message: 1 of 4

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.

Subject: calling value of variable from main program into myfun while using fsolve

From: Sean

Date: 21 May, 2010 13:06:04

Message: 2 of 4

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

Subject: calling value of variable from main program into myfun while using fsolve

From: deepak

Date: 21 May, 2010 15:54:04

Message: 3 of 4


can you please elaborate the procedure for doing that.

thnx

Subject: calling value of variable from main program into myfun while using fsolve

From: Sean

Date: 21 May, 2010 16:12:04

Message: 4 of 4

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

Tags for 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