为什么我不能使用开机功能?

Why cant I use power on functions?

我写了这段代码:

t=linspace(0,pi)
x = @(t)sin(t)

然后我试了这个->

x = power(x,2)

但是它给了我一个错误,那么我该如何在一个函数上使用 power 函数呢?

你不能。

但是,您可以在函数 的输出上使用幂函数

x = @(t)sin(t); %this is an anonymous function

t=linspace(0,pi); % this is an array

x2 = power(x(t),2); % this is an array

或者,您可以创建第二个函数来调用第一个函数

x2=@(t)power(x(t),2); % this is  an anonymous function