How to loop the fsolve for various sets of parameters

3 ビュー (過去 30 日間)
Nivedhitha S
Nivedhitha S 2019 年 5 月 1 日
編集済み: Stephan 2019 年 5 月 1 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by