我自己定义的多元函数输入向量报错。

代码如下:y{1}=@(x1,x2,x3)x1^2+x2^2+x3^2;
syms x1 x2 x3;
x0=[1,2,3];
out=y{1}(x0);
错误信息如下:[size=13.3333px]用于对矩阵求幂的维度不正确。请检查并确保矩阵为方阵并且幂为标量。要单独对矩阵的每个元素进行运算,请使用 POWER (.^)执行按元素求幂。
[size=13.3333px]有没有办法能解决这个问题?十分感谢。

 采纳的回答

BenYin
BenYin 2022-11-13

0 个投票

或者你这么定义,参考如下:
clear;clc
y{1}=@(x)x(1)^2+x(2)^2+x(3)^2;
syms x1 x2 x3;
x0=[1,2,3];
out=y{1}(x0)

更多回答(0 个)

类别

标签

Community Treasure Hunt

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

Start Hunting!