Adding input parameters to a function
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
So I have a function that uses fsolve to solve for two variables, lmb_1 and lmb_2. There are two other variables that I'd like to plug into the function. something like root2d(x, phi_0,k) so that I don't have to keep changing the phi_0 and k values in the root2d function.
function F = root2d(x)
phi_0=0.2;
k=0.1;
lmb_1=x(1);
lmb_2=x(2);
s_i = x(1);
s_ii = x(2);
expression_i = phi_0*(k - s_i) + k^2/2 - s_i^2/2 - lmb_1*lmb_2*(log(k) - log(s_i));
expression_ii = phi_0*s_ii - phi_0 - s_ii^2/2 + lmb_1*lmb_2*log(s_ii) + 1/2;
F(1) = expression_i-expression_ii;
F(2) = x(1)-x(2)+phi_0;
end
x0 = [1,1];
answer = fsolve(@root2d,x0)
0 Commenti
Risposte (1)
Walter Roberson
il 14 Mar 2017
2 Commenti
Walter Roberson
il 15 Mar 2017
phi_0 = 0.2;
k = 0.1;
x0 = [1 1];
F = fzero(@(x) Lambda1and2Solver_n_1(x, phi_0, k), x0);
function F = Lambda1and2Solver_n_1(x, phi_0, k)
lmb_1=x(1);
lmb_2=x(2);
s_i = x(1);
s_ii = x(2);
expression_i = phi_0*(k - s_i) + k^2/2 - s_i^2/2 - lmb_1*lmb_2*(log(k) - log(s_i));
expression_ii = phi_0*s_ii - phi_0 - s_ii^2/2 + lmb_1*lmb_2*log(s_ii) + 1/2;
F(1) = expression_i-expression_ii;
F(2) = x(1)-x(2)+phi_0;
end
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!