如何在matlab中编写这个求和
if k=1,..n
,并存储在k
的每次迭代中,即
修改
我尝试在符号
中使用解决方案clear;clc
h=0.1; x=0:h:2;n=10;m=3;
w = @(i,j,k) (-1)^(i+j)*cos((j*pi/h)*(x-x(k)));
syms I J
J=1:m;
for k=1:n
f(k)=symsum(symsum(w(I,J,k), J, 1, I), I, 1, m);
end
但是给我错误
Error using mupadmex
Error in MuPAD command: A square matrix is expected.
[(Dom::Matrix(Dom::ExpressionField()))::exp]
Error in sym/privBinaryOp (line 1693)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in sym/mpower (line 189)
B = privBinaryOp(A, p, 'symobj::mpower');
Error in @(i,j,k)(-1)^(i+j)*cos((j*pi/h)*(x-x(k)))
此外,我使用了具有循环条件的备用代码,但我不知道它是否正确
clear;clc
h=0.1; x=0:h:2;n=10;m=3;
w = @(i,j,k) (-1)^(i+j)*cos((j*pi/h)*(x-x(k)));
for k=1:n;
for i = 1:m;
for j = 1:i;
f(k)= sum(sum(w(i,j,k) ) );
end
end
end