FSOLVE requires all values returned by functions to be of data type double.

1 view (last 30 days)
Hi,
I have defined a simple function, to solve numerically a system of 3 equeations, 3 unknows, but I keep receiving this error:
FSOLVE requires all values returned by functions to be of data type double.
Shoul I use another solver due to myt equations?
here is the code
function [L, V, SP]=steadystate_helper(L0, V0, SP0, bet, tet, chi, tau)
x0=[L0; V0; SP0];
F=@(L, V, SP) [L-V/(tet-bet*(V*SP)); 1-chi*(SP*L+(1/bet))+tau*L; V-chi+(1-chi)*bet*V*(SP*L+(1/bet))];
options = optimset ('Display', 'Final', 'Tolx', 1e-10,'Tolfun',1e-10);
[L, V, SP]=fsolve(@(L, V, SP) F, x0, options);

Accepted Answer

Star Strider
Star Strider on 6 Mar 2021
Call the function with one parameter vector:
fcn = @(b) F(b(1),b(2),b(3));
and with that change, this works:
L0 = 3; % Create Value
V0 = 5; % Create Value
SP0 = 7; % Create Value
tet = rand; % Create Value
bet = rand; % Create Value
tau = rand; % Create Value
chi = rand; % Create Value
x0=[L0; V0; SP0];
F=@(L, V, SP) [L-V/(tet-bet*(V*SP)); 1-chi*(SP*L+(1/bet))+tau*L; V-chi+(1-chi)*bet*V*(SP*L+(1/bet))];
options = optimset ('Display', 'Final', 'Tolx', 1e-10,'Tolfun',1e-10);
fcn = @(b) F(b(1),b(2),b(3));
B = fsolve(fcn, x0, options)
Supply the correct scalar values to get the intended result.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!