0

我在 for 循环中有一些符号变量,然后出现一个错误,即

??? The following error occurred converting from sym to double:
  Error using ==> mupadmex
  Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
    If the input expression contains a symbolic variable, use the VPA function instead.

问题是我应该在计算结束时插入符号变量的值,因为它们是积分变量......我该如何解决这个问题???

function [product,Mi]=test(ii)
variables % this is just a numerical value for m, M and L
syms x y q B alp kk

product=zeros(3,1);
for i=1:3
for ni=1:9

n=new(ni); % All possible "n"s for each "ni" here new(ni) a function which gives different size matrix each time in the for loop 

n_vector=zeros(1,3);

for jj=1:size(n,1)

    n_vector(:)=n(jj,:);




p_vector=((2*pi/L)*(n_vector));
q_vector=((L/(2*pi))*[1,0,0]);
A=zeros(1,3);

    if ii==1
        Mi=sqrt(x.^2*M^2+(1-x).*m^2);
        A=y.*p_vector;
    elseif ii==2
        Mi=sqrt(m^2-(x.*(1-x)).*q^2);
        A=x.*q_vector;
    elseif ii==3
        Mi=sqrt((y.^2).*(M^2-(x.*(1-x)).*q^2)+(1-y).*m^2);        
        A=y.*(p_vector-q_vector*x);
    elseif ii==4
        Mi=sqrt((1-y).^2*M^2+y.^2*m^2-(x.*(1+x)).*y^2*q^2);    
        A=(1-y).*p_vector-(x.*y).*q_vector;
    end

        if i==1
           product(i,1)=A(1,1)*n_vector(1,1)    
        else
           product(i,1)=A(i,1)*n_vector(1,i)
        end

end
end
end
end

这里只是我函数的一部分......我知道“产品”看起来很奇怪,我的意思是我可以编写一个没有 for 循环的表达式,但实际上在我的函数中我需要一个 for 循环,每个产品都是这样的......

4

1 回答 1

1

您无法分配的原因A(1,1)*n_vector(1,1)product(i,1)因为product已被定义为双精度数组。

不管用:

product = zeros(3, 1)
product(1,1) = sym('A')

  The following error occurred converting from sym to double:
  Error using mupadmex
  Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
  If the input expression contains a symbolic variable, use the VPA function instead.

将工作:

product=cell(3,1);
product(i,1) = {sym('A')}
product(2,1) = {sym('B')}
product(3,1) = {sym('C')}
于 2013-05-24T13:45:40.327 回答