简体   繁体   中英

how to solve nonlinear equations in MATLAB cyclically

I want to solve binary quadratic equations in MATLAB for 5401 times. Every time I only change one parameter in the equations. I can't find a good way to work this out. Here is the code.

function F = root2d(x)
w2 = 5.67*10^-8*0.00001/(1/0.9+1/0.95-1);
w2_ = w2/0.028;
w3 = 5.6*0.00001;
w3_ = w3/0.028;
F(1) = 0.045*x(1)-(w3+0.045)*x(2)+w3*(**37**+273.15)-w2*(x(2)^4-(**37**+273.15)^4);
F(2) = -w3_*x(1)+w3_*(**37**+273.15)-w2_*(x(2)^4-(**37**+273.15)^4);


x0 = [310.15, 310.15];
x = fsolve(@root2d, x0);
T(1, 1) = x(1);    
T(2, 1) = x(2);

I have a 5401*1 matrix which contains the data I want to use. For example, in the next equation, I want to use the number '38' to replace '37' and get a new solution and save it in another matrix. And then use '55' to replace '38'. Keep cycling like this until all the numbers in the matrix are used. Finally, what I want is a matrix which contains solutions for each group. Any good idea?

You can pass your parameter like this: x = fsolve(@(x) root2d(x, param), x0);

So your root2d function will be:

function F = root2d(x,param)
w2 = 5.67*10^-8*0.00001/(1/0.9+1/0.95-1);
w2_ = w2/0.028;
w3 = 5.6*0.00001;
w3_ = w3/0.028;
F(1) = 0.045*x(1)-(w3+0.045)*x(2)+w3*(param+273.15)-w2*(x(2)^4-(param+273.15)^4);
F(2) = -w3_*x(1)+w3_*(param+273.15)-w2_*(x(2)^4-(param+273.15)^4);

and your script will be:

% Assume paramvector is the 5401*1 matrix containing the data you want to use.
x0 = [310.15, 310.15];
for i = 1:numel(paramvector)
    T(i) = fsolve(@(x) root2d(x, paramvector(i)), x0).';
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM