fsolve with structure of functions in a cell

Hi,
I'm trying to solve a structure of 10 equations using fsolve, but so far, Matlab refuses to use my cell as input:
eq =
Columns 1 through 5
[function_handle] [function_handle] [function_handle] [function_handle] [function_handle]
Columns 6 through 10
[function_handle] [function_handle] [function_handle] [function_handle] [function_handle]
Error using lsqfcnchk (line 114)
FUN must be a function handle.
Error in fsolve (line 198)
funfcn = lsqfcnchk(FUN,'fsolve',length(varargin),funValCheck,gradflag);
Error in NRTL (line 36)
fsolve({eq{1}; eq{2}; eq{3}; eq{4}; eq{5}; eq{6}; eq{7}; eq{8}; eq{9}; eq{10}},[0,0 0,0 0,0 0,0 0,0 0,0 0,0
0,0 0,0],options)
Matlab code (simplified):
modelRaf(i) = (((T(1,i).*G(1,i).*x_raf(1,j)) + (T(2,i).*G(2,i).*x_raf(2,j)) ... % a very long model
for i=1:2
eq{i} = str2func(['@(T) exp(',char(modelRaf(i)),') .* ',num2str(x_raf(2,i))]
end
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);
fsolve(eq,[0,0 0,0],options)
The model works (used it many times). Any sugestions?

 Akzeptierte Antwort

Alan Weiss
Alan Weiss am 27 Mai 2016

2 Stimmen

I think that the error message is clear: fsolve expects a single function handle, not a cell array of handles.
fsolve is for solving N equations in N unknowns. If your 10 equations are functions of the same 10 variables, then rewrite your system to a function that accepts exactly one 10-dimensional input variable x and outputs a 10-dimensional result F(x). For example,
fun = @(x)[fun1(x),...,fun10(x)]
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Weitere Antworten (1)

Peter
Peter am 23 Apr. 2018

0 Stimmen

This topic can be closed.
It is already a while ago that I worked on this, but I solved it with Alan's answer, "matlabFunction()" to split the formula in chunks, and some iterative calculations to test the convergence.
Thanks! Peter

1 Kommentar

We leave solved problems available so that other people can learn from them.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by