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:
how to call values from main code in fsolve

Subject: how to call values from main code in fsolve

From: deepak

Date: 20 Jun, 2010 09:41:05

Message: 1 of 2

Hi,
I am trying to call the value of a variable in the function while using fsolve.This variable changes it's value every time so it can't be defined in the code of function itself.

for example if function is defined as

function F=myfunt(x)
F=[x(1)^2 +x(2)+x(3)-c(1);x(2)^2 +x(1)+x(3)-c(2); x(1)^2 +x(3)+x(2)-c(3)];

in this case i want function to take value of vector c from main program. How can i do this.

Thnx and regards,

Deepak

Subject: how to call values from main code in fsolve

From: Gang-Gyoo

Date: 20 Jun, 2010 10:30:08

Message: 2 of 2

Hi,

The following is a piece of code which you may want.

Gang-Gyoo

----------------------------------------------------------------------------
function test
x0= [1;2;3] %define initial vector x0
for i= 1:10 % put the statement 'if' if you want
    c= [1;2;3]; %define vector c
    x= fsolve(@(x) myfunt(x,c),x0)
end

function F= myfunt(x,c)
F= [x(1)^2 +x(2)+x(3)-c(1);x(2)^2 +x(1)+x(3)-c(2); x(1)^2 +x(3)+x(2)-c(3)];

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