Undefined function 'power' for input arguments of type 'function_handle'. for some Implicit function
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Vainshtein
el 7 de Abr. de 2021
Editada: Cris LaPierre
el 7 de Abr. de 2021
I'm trying to plot a "little bit" complicated Implicit function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/576082/image.png)
for g=1.5 and f=1;
my code was:
g=1.5; %GN
f=1; %epsilon_1
Fun=@(x,y) sqrt((x.^2-y.^2+g^2-f^2)^2+4*x.*y)+g^2+(g*sqrt(2*(x.^2-y.^2+g^2-f^2+sqrt((x.^2-y.^2+g^2-f^2)^2+4*x.*y))))/(tanh((sqrt(2*(x.^2-y.^2+g^2-f^2+sqrt((x.^2-y.^2+g^2-f^2)^2+4*x.*y)))/(g))))
fimplicit(Fun)
but I got the Error code:
Undefined function 'power' for input arguments of type 'function_handle'.
Can anyone please help me to understand what to do in this case?
5 comentarios
Daniel Vainshtein
el 7 de Abr. de 2021
Editada: Daniel Vainshtein
el 7 de Abr. de 2021
Respuesta aceptada
Cris LaPierre
el 7 de Abr. de 2021
Editada: Cris LaPierre
el 7 de Abr. de 2021
I'm not able to recreate the same error message. It would appear the code you have shared here does not match the code you are running that is creating the error. Specifically, no function handle is being raised to a power in your example.
I do get a warning with your example about array inputs. To fix this, use elementwise operators where appropriate
Fun=@(x,y) sqrt((x.^2-y.^2+g^2-f^2).^2+4*x.*y)+g^2+(g*sqrt(2*(x.^2-y.^2+g^2-f^2+sqrt((x.^2-y.^2+g^2-f^2).^2+4*x.*y))))./(tanh((sqrt(2*(x.^2-y.^2+g^2-f^2+sqrt((x.^2-y.^2+g^2-f^2).^2+4*x.*y)))/(g))));
% ^^ ^^ ^^ ^^
I can recreate your error message if I break the equation into smaller equations, and combine them to form the bigger equation. Here, the fix is to include the (x,y) inputs when using the handle.
% Works
g=1.5; %GN
f=1; %epsilon_1
eq1 = @(x,y) x.^2-y.^2+g^2-f^2;
eq2 = @(x,y) sqrt(eq1(x,y).^2+4*x.*y);
Fun = @(x,y) eq2(x,y) + g^2 + g*sqrt(2*(eq2(x,y) + eq1(x,y)))./(tanh(sqrt(2*(eq2(x,y) + eq1(x,y)))/g));
fimplicit(Fun)
% Causes error
eq2 = @(x,y) sqrt(eq1.^2+4*x.*y);
% ^ removed the (x,y) inputs. Now code is trying to square a function handle, resulting in an error.
Fun = @(x,y) eq2(x,y) + g^2 + g*sqrt(2*(eq2(x,y) + eq1(x,y)))./(tanh(sqrt(2*(eq2(x,y) + eq1(x,y)))/g));
fimplicit(Fun)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots 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!