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

代码如下: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]有没有办法能解决这个问题?十分感谢。

 Réponse acceptée

BenYin
BenYin le 13 Nov 2022

0 votes

或者你这么定义,参考如下:
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)

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!