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:
varying number of variables to solve for in fsolve

Subject: varying number of variables to solve for in fsolve

From: Christian

Date: 3 Apr, 2014 04:36:11

Message: 1 of 2

Hi all,

I have a system of equations that I'd like to solve using fsolve. Suppose I have x equations and therefore insert x initial guesses. Sometimes I fix some (let's say y<x) of the variables ex ante and eliminate y equations from the system. I still would like to use fsolve with the same function file to solve for the remaining x-y variables. Is there a way I can tell fsolve which equations to keep in the system and which variables to solve for, or do I have to write a new function file with only x-y equations?

I hope my problem is clear.
Thanks for your help,
Christian

Subject: varying number of variables to solve for in fsolve

From: Steven Lord

Date: 3 Apr, 2014 13:53:58

Message: 2 of 2


"Christian " <proechri@umich.edu> wrote in message
news:lhiofr$cgp$1@newscl01ah.mathworks.com...
> Hi all,
>
> I have a system of equations that I'd like to solve using fsolve. Suppose
> I have x equations and therefore insert x initial guesses. Sometimes I fix
> some (let's say y<x) of the variables ex ante and eliminate y equations
> from the system. I still would like to use fsolve with the same function
> file to solve for the remaining x-y variables. Is there a way I can tell
> fsolve which equations to keep in the system and which variables to solve
> for, or do I have to write a new function file with only x-y equations?

There's no option in FSOLVE to do this but you can do this in your objective
function using something like:


function y = myobjective(paramLoc, paramVal, fixedLoc, fixedVal);
x(paramLoc) = paramVal;
x(fixedLoc) = fixedVal;
x = reshape(x, [], 1); % It's often convenient to work with a column vector
% Now use x to compute y


You would use this as:


sol = fsolve(@(z) myobjective([1 3 5], z, [2 4], [pi, exp(1)]), [10; 11;
12])


For the example above, the x you would use to compute inside myobjective is:

[z(1);
pi;
z(2);
exp(1);
z(3)]


--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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