FZERO cannot continue because user-supplied function_handle, A and B must be floating-point scalars.

12 visualizaciones (últimos 30 días)
My code is:
p=0.51:0.001:1.013;
fun1 = @(x) x.^2.*exp(-x)./(1-exp(-10));
fun2 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).^2.*exp(-x)./(1-exp(-10));
fun3 = @(u) integral(@(x) fun1(x),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun2(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);
fun11 = @(x) x.*exp(-x)./(1-exp(-10));
fun21 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).*exp(-x)./(1-exp(-10));
fun31 = @(u) integral(@(x) fun11(x),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun21(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);
fun4 = @(x,u) (20-x+fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10])-p)^0.5.*exp(-x)./(1-exp(-10));
fun44= @(u) integral(@(x) (20-p).^0.5.*exp(-x)./(1-exp(-10)),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun4(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);
fun51 =@(p) p - feval(fun31,fzero(@(u) fun3(u)-0.9973,[0.02,1]));
fun52 =@(p) feval(fun44,fzero(@(u) fun3(u)-0.9973,[0.02,1])) - integral(@(x) (20-x).^0.5.*exp(-x)./(1-exp(-10)),0,10);
plot3(p,fun51(p),fun52(p))
format long
Here is the error I get:
FZERO cannot continue because user-supplied function_handle ==> @(u)fun3(u)-0.9973 failed with the error below.
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
I am sorry that my function is a little bit messy. But I am worried about that you may miss some information if I simplify it. Any help is appreciated, thanks!

Respuesta aceptada

Torsten
Torsten el 10 de En. de 2019
Make a loop over the elements of p.
"fzero" cannot determine zeros of vector-valued functions (like in fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]) in fun2).
  4 comentarios
Walter Roberson
Walter Roberson el 10 de En. de 2019
Just accept Torsten's answer, since he provided the key about looping over p.

Iniciar sesión para comentar.

Más respuestas (2)

madhan ravi
madhan ravi el 10 de En. de 2019
Put .^ instead of ^
  2 comentarios
James_111
James_111 el 10 de En. de 2019
Thanks. I change it, now the error becomes:
FZERO cannot continue because user-supplied function_handle ==> @(u)fun3(u)-0.9973 failed with the error below.
A and B must be floating-point scalars.
Error in CaseB>@(p)p-feval(fun31,fzero(@(u)fun3(u)-0.9973,[0.02,1]))
Error in CaseB (line 29)
plot3(p,fun51(p),fun52(p))
James_111
James_111 el 10 de En. de 2019
Now the code is:
p=0.51:0.001:1.013;
fun1 = @(x) x.^2.*exp(-x)./(1-exp(-10));
fun2 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).^2.*exp(-x)./(1-exp(-10));
fun3 = @(u) integral(@(x) fun1(x),0,0.5./(20-p).^0.5./(2.*u))+integral(@(x) fun2(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);
fun11 = @(x) x.*exp(-x)./(1-exp(-10));
fun21 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).*exp(-x)./(1-exp(-10));
fun31 = @(u) integral(@(x) fun11(x),0,0.5./(20-p).^0.5./(2.*u))+integral(@(x) fun21(x,u),0.5./(20-p).^0.5./(2.*u),10,'arrayvalued', true);
fun4 = @(x,u) (20-x+fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10])-p).^0.5.*exp(-x)./(1-exp(-10));
fun44= @(u) integral(@(x) (20-p).^0.5.*exp(-x)./(1-exp(-10)),0,0.5./(20-p).^0.5./(2.*u))+integral(@(x) fun4(x,u),0.5./(20-p).^0.5./(2.*u),10,'arrayvalued', true);
fun51 =@(p) p - feval(fun31,fzero(@(u) fun3(u)-0.9973,[0.02,1]));
fun52 =@(p) feval(fun44,fzero(@(u) fun3(u)-0.9973,[0.02,1])) - integral(@(x) (20-x).^0.5.*exp(-x)./(1-exp(-10)),0,10);
plot3(p,fun51(p),fun52(p))
format long
Error is:
FZERO cannot continue because user-supplied function_handle ==> @(u)fun3(u)-0.9973 failed with the error below.
A and B must be floating-point scalars.
Any help is really appreciated, thanks!

Iniciar sesión para comentar.


Andrea
Andrea el 31 de Mzo. de 2023
AUXILIOOO COMO RESUELVO ESTO?
Error using fzero>localFirstFcnEvalError FZERO cannot continue because user-supplied function_handle ==> @(t)((R*t)/(Vmol-b))-((psi*((R^2*Tc^2*(((1+(0.48+(1.574*w)-(0.176*w^2))*(1-sqrt(t/Tc))))^2))/Pc))/((Vmol+(epsilon*b))*(V+(sigma*b))))-P failed with the error below. Error: File: V.m Line: 49 Column: 9 Using 'V' as both the name of a variable and the name of a script is not supported.
  1 comentario
Torsten
Torsten el 31 de Mzo. de 2023
Editada: Torsten el 31 de Mzo. de 2023
Using 'V' as both the name of a variable and the name of a script is not supported.
El mensaje de error es obvio. Cambie el nombre de la variable "V" en su código o asigne a su secuencia de comandos un nombre diferente.
Y dado que el identificador de su función se llamará con vectores para t, debe usar la multiplicación y división por componentes (.* y ./) en lugar de la multiplicación normal en los casos en que sea necesario.

Iniciar sesión para comentar.

Categorías

Más información sobre Nonlinear Optimization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by