Undefined function 'power' for input arguments of type 'function_handle'. for some Implicit function
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Daniel Vainshtein
le 7 Avr 2021
Modifié(e) : Cris LaPierre
le 7 Avr 2021
I'm trying to plot a "little bit" complicated Implicit function:
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?
Réponse acceptée
Cris LaPierre
le 7 Avr 2021
Modifié(e) : Cris LaPierre
le 7 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!