matlab 自定义函数调用

来源:百度知道 编辑:UC知道 时间:2024/05/24 02:43:08
定义函数 fun.m
function y=fun(x1,x2)
syms x1 x2;
y=x1^2+4*x2^2;

调用y=fun(2,2)显示错误!

你的x1, x2是函数的参数,不需要再次定义
这样就可以了

function y=fun(x1,x2)
y=x1^2+4*x2^2;

如果非的要符号计算,试一试下面的:
function y=fun(x11,x21)
syms x1 x2;
y=x1^2+4*x2^2;

sub(y,x1,x2,x11,x21)