【问题标题】:Why cant I use power on functions?为什么我不能使用开机功能?
【发布时间】:2019-05-29 10:39:45
【问题描述】:

我写了这段代码:

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

然后我尝试了这个->

x = power(x,2)

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

【问题讨论】:

    标签: matlab exponent


    【解决方案1】:

    你不能。

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

    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
    

    【讨论】:

    • 也就是说,我希望这是一个例子。将函数sin重新定义为x是没有意义的,直接使用函数sin就好了。
    • sin(t).^2 或 sin(linspace(0,pi)).^2 是其他选择,具体取决于后续使用 --- 请参阅 power
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 2017-03-15
    • 1970-01-01
    • 2018-12-10
    相关资源
    最近更新 更多