how to use fsolve with more equation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function F = fullfun(S_c,S_d,Ru,T,mu_s0,mu_w0,F,lambda_0,alpha,C_c,C_d,V_cp,r_am,r_cm,b_d,sigma_d,sigma_c,N_cp,h_r,sigma)
F = [T_s+(4*10^(-6)*S_d^(2))-(4*10^(-5)*S_d)-0.96;
T_w+(4*10^(-5)*S_c^(2))+(1.9*10^(-2)*S_c)-11.2;
L_s-(min(2*10^(-12)*S_d^(2)-3*10^(-10)*S_d+...
6*10^(-8),2*10^(-12)*S_c^(2)-3*10^(-10)*S_c+6*10^(-8)));
L_w-(5*10^(-4)*S_c^(-0.416));
mu_sc-(mu_s0+Ru*T*log(S_c/1000));
mu_sd-(mu_s0+Ru*T*log(S_d/1000));
mu_wc-(mu_w0+Ru*T*log((1000-S_c)/1000));
mu_wd-(mu_w0+Ru*T*log((1000-S_d)/1000));
E_m-(T_s/F*(mu_sc-mu_sd)+T_w/F*(mu_wc-mu_wd));
E_am-E_m;
E_cm-E_m;
lambda_c-lambda_0+alpha*sqrt(C_c);
lambda_d-lambda_0+alpha*sqrt(C_d);
lambda_r-((lambda_c + lambda_d)/2);
C_r-((C_c+C_d)/2);
k-(lambda_r * C_r);
I-((V_cp-E_am-E_cm)/(r_am+r_cm+b_d/(sigma_d*lambda_d*C_d)+(b_c/(sigma_c*lambda_c*C_c))+...
r_cm/N_cp+2*h_r/(sigma*k*N_cp)));
J_s-(T_s*I/F - L_s*(C_c-C_d));
J_w-(T_w*I/F + L_w*Ru*T*(C_c-C_d)*10^(-5)*2);
0 comentarios
Respuestas (2)
Walter Roberson
el 21 de Sept. de 2019
Bundle all of the variables into a single vector for the purposes of fsolve. You can unbundle them inside the function.
vars20init = vector of 20 initial values
sol = fsolve(@fullfun, vars20init)
function result = fullfun(vars20)
tcell = num2cell(vars20);
[S_c,S_d,Ru,T,mu_s0,mu_w0,F,lambda_0,alpha,C_c,C_d,V_cp,r_am,r_cm,b_d,sigma_d,sigma_c,N_cp,h_r,sigma] = tcell{:};
result = [T_s+(4*10^(-6)*S_d^(2))-(4*10^(-5)*S_d)-0.96;
T_w+(4*10^(-5)*S_c^(2))+(1.9*10^(-2)*S_c)-11.2;
L_s-(min(2*10^(-12)*S_d^(2)-3*10^(-10)*S_d+...
6*10^(-8),2*10^(-12)*S_c^(2)-3*10^(-10)*S_c+6*10^(-8)));
L_w-(5*10^(-4)*S_c^(-0.416));
mu_sc-(mu_s0+Ru*T*log(S_c/1000));
mu_sd-(mu_s0+Ru*T*log(S_d/1000));
mu_wc-(mu_w0+Ru*T*log((1000-S_c)/1000));
mu_wd-(mu_w0+Ru*T*log((1000-S_d)/1000));
E_m-(T_s/F*(mu_sc-mu_sd)+T_w/F*(mu_wc-mu_wd));
E_am-E_m;
E_cm-E_m;
lambda_c-lambda_0+alpha*sqrt(C_c);
lambda_d-lambda_0+alpha*sqrt(C_d);
lambda_r-((lambda_c + lambda_d)/2);
C_r-((C_c+C_d)/2);
k-(lambda_r * C_r);
I-((V_cp-E_am-E_cm)/(r_am+r_cm+b_d/(sigma_d*lambda_d*C_d)+(b_c/(sigma_c*lambda_c*C_c))+...
r_cm/N_cp+2*h_r/(sigma*k*N_cp)));
J_s-(T_s*I/F - L_s*(C_c-C_d));
J_w-(T_w*I/F + L_w*Ru*T*(C_c-C_d)*10^(-5)*2);]
end
I notice you use F as both input and output. That is unlikely to be a good idea when you are calling fsolve with the function.
2 comentarios
Walter Roberson
el 22 de Sept. de 2019
You use T_s in your function, but it is not a parameter to the function. Where do you want your code to find T_s from?
chirag patel
el 23 de Sept. de 2019
3 comentarios
Walter Roberson
el 23 de Sept. de 2019
Okay, go ahead. Follow the same strategy as before: all inputs should go into a single vector, and when you get the vector output from the solver, break it up into meaningful variables. Inside the function to be solved, expect everything as a single input, and break the values out into meaningful variables (this is what the num2cell and {:} is for)
Ver también
Categorías
Más información sobre Signal Integrity Kits for Industry Standards en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!