fsolve - How do I input known variables and still make a guess at the unknown variables in fsolve?

Hi,
I am working with 6 highly non-linear equations in which I define two variables (A1 and A2), input 4 variables from the previous timestep (B1 -> B4), and using the fsolve command, have a guess at 6 values, 4 of which will become the new B1->B4 values for the next timestep (C1->C4), and 2 which I am actually interested in (D1 D2).
I have my code in the form:
function EoM = myfun(...) % the inputs to this are numerous and not all of them will be guessed, some are in the form of arrays
% Define a series of coefficients and use them with the inputs to determine the equations to be used by fsolve
EoM = [/*some function including A1, A2, B1, B2, B3, B4, C1, C2, C3, C4, D1, D2*/;...
/*another function including A1, A2, B1, B2, B3, B4, C1, C2, C3, C4, D1, D2*/;...
. ;...
. ;...
. ;...
/*the final equation*/];
end
Guess = [C1 C2 C3 C4 D1 D2]
Ouput = fsolve(@myfun,Guess)
if true
% code end
I guess my question is, will this work or will fsolve be looking for guesses at the other values?
cheers for any help

 Accepted Answer

You should use anonymous functions to tell FSOLVE which parameters are known/fixed and which are unknowns to be solved for. In other words, your code should look something like this
function EoM = myfun(UnKnowns,Fixed)
tmp=num2cell(Unknowns);
[C1,C2,C3,C4,D1,D2]= deal(Unknowns{:});
tmp=num2cell(Fixed);
[B1,B2,B3,B4,A1,A2] = deal(Fixed{:});
EoM = ...
end
Guess = [C1 C2 C3 C4 D1 D2];
Fixed= [B1,B2,B3,B4,A1,A2];
Ouput = fsolve(@(Unknowns)myfun(Unknowns,Fixed), Guess)

4 Comments

Thank you very much for this.
A quick question on Syntax - what does the @ signify? Is this a pointer of sorts?
@ has a number of different meanings in MATLAB. In this case, it is used to define an Anonymous Function, which hopefully you've read about by now
I have indeed, I was just wondering. Thanks again

Sign in to comment.

More Answers (0)

Categories

Asked:

on 19 Apr 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!