# 5 麦片

050

2主题 0最佳答案

 本帖最后由 tanmin 于 2019-6-10 21:28 编辑 请大家指导指导： 运行报错信息如下： 无法从 sym 转换为 logical。 出错 M (line 65)     while differ>eps 代码如下：clc[/size] [size=2]clear[/size] [size=2]%Newton iteration-Multi Points[/size] [size=2] [/size] [size=2]syms x1 x2 x3 x4 x5 x6 sum_n n_NaF n_AlF3;[/size] [size=2]syms RR;[/size] [size=2]syms N[/size] [size=2]RR=ones(1,7)/10e11;[/size] [size=2] [/size] [size=2] [/size] [size=2]%****************[/size] [size=2]T=['n_AlF3  ','x1  ', 'x2  ', 'x3  ', 'x4  ', 'x5  ', 'x6  ','n_sum  '];        %[/size] [size=2]disp(T);[/size] [size=2] [/size] [size=2]N=0;[/size] [size=2]for n_AlF3=0.01:0.01:0.5;                %%[/size] [size=2]    [/size] [size=2]    disp(n_AlF3);[/size] [size=2]    disp('--------');[/size] [size=2]    [/size] [size=2]    if N==0[/size] [size=2]        s1=1-3*n_AlF3;[/size] [size=2]        s2=0;[/size] [size=2]        s3=0;[/size] [size=2]        s4=n_AlF3/3;[/size] [size=2]        s5=0;[/size] [size=2]        s6=1-n_AlF3;[/size] [size=2]        s7=0;[/size] [size=2]    elseif N>0[/size] [size=2]        s1=RR(1);[/size] [size=2]        s2=RR(2);[/size] [size=2]        s3=RR(3);[/size] [size=2]        s4=RR(4);[/size] [size=2]        s5=RR(5);[/size] [size=2]        s6=RR(6);[/size] [size=2]        s7=RR(7);[/size] [size=2]    end[/size] [size=2]    [/size] [size=2]    eps=1.0e-6;[/size] [size=2]    differ=1;[/size] [size=2]    n=1;[/size] [size=2]    [/size] [size=2]    f1=x1*x3-0.2471*sum_n*x2; %0.247146 改为0.2471[/size] [size=2]    f2=x1*x4-0.1352*sum_n*x3;%0.135198 改为0.1352[/size] [size=2]    f3=x1*x5-0.0003*x4^2; %0.000299 改为0.0003[/size] [size=2]    f4=x1+6*x2+5*x3+4*x4+7*x5+14*x6-( n_NaF+3*n_AlF3);[/size] [size=2]    f5=x2+x3+x4+2*x5+3*x6-n_AlF3;[/size] [size=2]    f6=x1+x2+x3+x4+x5+x6-sum_n;[/size] [size=2]    f7=x4^2*x2-0.0000008*x6*sum_n^2;[/size] [size=2]    F=[f1 f2 f3 f4 f5 f6 f7];[/size] [size=2]    [/size] [size=2]    dF=transpose([diff(F,'x1');diff(F,'x2') ;diff(F,'x3');diff(F,'x4');diff(F,'x5'); diff(F,'sum_n'); diff(F,'x6')]);[/size] [size=2]    [/size] [size=2]    x0 = [s1,s2,s3,s4,s5,s6,s7];[/size] [size=2]    [/size] [size=2]    Fx = subs(F,[x1 x2 x3 x4 x5 sum_n x6],x0);[/size] [size=2]    dFx = subs(dF, [x1 x2 x3 x4 x5 sum_n x6],x0);[/size] [size=2]    %disp('*******************');[/size] [size=2]    %disp(vpa(Fx));[/size] [size=2]    %disp(vpa(dFx));[/size] [size=2]    [/size] [size=2]    r= transpose(x0)- inv(dFx)*transpose(Fx);[/size] [size=2]    %disp(vpa(r));[/size] [size=2]    [/size] [size=2]    while differ>eps[/size] [size=2]        %disp('*******************');[/size] [size=2]        Fx = subs(F, [x1 x2 x3 x4 x5 sum_n x6], transpose(r));[/size] [size=2]        dFx = subs(dF, [x1 x2 x3 x4 x5 sum_n x6], transpose(r));[/size] [size=2]        %disp(vpa(Fx));[/size] [size=2]        %disp(vpa(dFx));[/size] [size=2]        [/size] [size=2]        differ=norm( inv(dFx)*transpose(Fx));[/size] [size=2]        [/size] [size=2]        r=r-inv(dFx)*transpose(Fx);[/size] [size=2]        [/size] [size=2]        %disp(vpa(r));[/size] [size=2]        [/size] [size=2]        n =n+1;[/size] [size=2]        if(n>100);[/size] [size=2]            disp('iteration exceed! Not converged!');[/size] [size=2]            return;[/size] [size=2]        end;[/size] [size=2]    end;[/size] [size=2]    [/size] [size=2]    %r=[n_AlF3,r];[/size] [size=2]    RR=vpa(transpose(r));[/size] [size=2]    disp(RR);[/size] [size=2]    N=N+1;[/size] [size=2]end;[/size] 复制代码

# 5 麦片

050

2主题 0最佳答案
楼主| 发表于 2019-6-10 21:51:16 | 显示全部楼层
 该问题已解决
 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页