fsolve with another function

3 visualizaciones (últimos 30 días)
beginner
beginner el 12 de Mzo. de 2016
Comentada: Star Strider el 12 de Mzo. de 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!!!

Respuesta aceptada

Star Strider
Star Strider el 12 de Mzo. de 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 comentarios
beginner
beginner el 12 de Mzo. de 2016
my mistake!! it works! thanks!
Star Strider
Star Strider el 12 de Mzo. de 2016
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics 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!

Translated by