Undefined function 'power' for input arguments of type 'function_handle'. for some Implicit function

15 次查看(过去 30 天)
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?
  5 个评论
Daniel Vainshtein
编辑:Daniel Vainshtein 2021-4-7
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((1/g)*(sqrt(2*(x.^2-y.^2+g^2-f^2+sqrt((x.^2-y.^2+g^2-f^2)^2+4*x.*y))))))

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2021-4-7
编辑:Cris LaPierre 2021-4-7
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)
Warning: Error updating ImplicitFunctionLine.

Undefined function 'power' for input arguments of type 'function_handle'.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by