How to loop the fsolve for various sets of parameters

2 次查看(过去 30 天)
I have four different non linear equations to solve for 4 unknowns. The known parameters in the equations vary and i have around 1000 such sets of parameters. How to use fsolve to solve for these various parameter sets and store separate values for the unknowns (say r1,r2,r3,r4)? I am able to solve for 1 set of parameters and I am unable to figure out how to use different sets of paarameters. I tried looping in the fsolve but I am not sure how to proceed. Any help would be great!
Thanks.
%CODE FOR EQUATION SOLVING
%one set of parameters p1,p2,p3 are illustrated here
function F= eq(r)
F(1)= (62624.20783*4*(8.854e-12))-(9*r(4)*r(2)*0.01); %the value 62624.20783 is p1 (has 1000 different values)
F(2)= (46383.18112*r(2)*(0.001)*((2*r(3))+0.15))-(2*r(3)*0.15); % the value 46383.18112 is p2
F(3)= (r(3)*(1-r(4)).^(1.5))- (1.36640009); % the value 1.36640009 is p3
F(4)= r(4)-((4/3)*3.14*((r(2)).^3)*r(1));
end
%code for solving the equations
fun=@eq;
r0=[10000 1E-6 10 2E-15]; %initial guess
options = optimoptions('fsolve','Display','iter','MaxFunEvals',50000, 'MaxIter',1000);
[r,fval,exitflag,output] = fsolve(fun,r0,options);

采纳的回答

Stephan
Stephan 2019-5-1
编辑:Stephan 2019-5-1
Hi,
store the parameters in an array and call fsolve in a loop. In every run of the loop you solve for one set of parameters. The results are also stored in an array, indexed by the loop counter variable too. Dont forget to preallocate.
Best regards
Stephan

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by