fsolve with another function

3 views (last 30 days)
beginner
beginner on 12 Mar 2016
Commented: Star Strider on 12 Mar 2016
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!!!

Accepted Answer

Star Strider
Star Strider on 12 Mar 2016
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 Comments
beginner
beginner on 12 Mar 2016
my mistake!! it works! thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!