fsolve with another function

1 次查看(过去 30 天)
Hey,
I have a function which looks like:
function F = ex5(A_CL)
% Constants
theta = 86/180*pi;
delta_GL = 3.28*10^-10; %[m]
gamma_L = 0.0728; %[J/m^2]
N = Inf;
% equation to solve
F = gamma_L*(1+cos(theta))-vdW_layer(delta_GL, A_CL,N);
end
This function calls up another funcition vdW-layer(delta_GL, A_CL, N).
Now I want to solve the function/ find out the A_CL, having delta_GL and N as input variables and A_CL remains unknown.
I tried with this code:
fun5 = @(A_CL) ex5(A_CL);
A_CL_init = 10e-78; %initial guess
[A_CL, fval] = fsolve(fun5, A_CL_init);
where is my mistake??
thanks a lot!!!

采纳的回答

Star Strider
Star Strider 2016-3-12
You have to edit your ‘ex5’ function to allow it to use extra input arguments:
function F = ex5(A_CL, delta_GL, N)
% Constants
theta = 86/180*pi;
% % delta_GL = 3.28*10^-10; %[m] % Now An Input Argument, So Delete Here
gamma_L = 0.0728; %[J/m^2]
% % N = Inf; % Now An Input Argument, So Delete Here
% equation to solve
F = gamma_L*(1+cos(theta))-vdW_layer(delta_GL, A_CL,N);
end
Then this changes to accommodate the new inputs to ‘ex5’:
delta_GL = . . .;
N = . . .;
fun5 = @(A_CL) ex5(A_CL, delta_GL, N);
A_CL_init = 10e-78; %initial guess
[A_CL, fval] = fsolve(fun5, A_CL_init);
Note: I did not run your code, so I’m labeling my changes as UNTESTED CODE, however it should work.
  3 个评论
beginner
beginner 2016-3-12
my mistake!! it works! thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by