MATLAB错误-“Error using symengine Input arguments must be converted to floating-point numbers”

xxhby3vn  于 2023-11-21  发布在  Matlab
关注(0)|答案(1)|浏览(349)

我正在编写一个MATLAB代码来动画一个grashof四杆机构,但我的动画只运行到第15次迭代,并返回此错误错误使用symengine输入参数必须转换为浮点数。
错误在sym/mupadmexnout(行1116)out = mupadmex(fcn,args{:});
错误在sym/max(行182)[C,I] = mupadmexnout('symobj::maxmin',Xsym,dim,'max',nanflag);
相关文件

有没有一种方法可以在两个参数都未知的情况下使用peicewise而不是max?非常感谢您的帮助和建议。

a=1.6;
b=2.14;
c=2.06;
d=3.5;
AB=a
BC=b
CD=c
AD=d
xa=0;
ya=0;
yd=0;
xd=AD;
t2=0
for ii=1:36
    syms t3 t4

    t2=t2+10
    f=a*cosd(t2) + b*cosd(t3) - c*cosd(t4) -3.5

    g=a*sind(t2) + b*sind(t3) - c*sind(t4)

    [t31, t41]=(solve(f==0,g==0,t3,t4))
    var = vpa(t31)

    th3=double((max(t31)))

    th4=double((max(t41)))
    
    if exist('th3', 'var') 
        xb(ii)=AB*cosd(t2);
        yb(ii)=AB*sind(t2);
        xc(ii)=xb(ii)  + BC*cosd(th3)
        yc(ii)=yb(ii)  + BC*sind(th3)
        
        plot(xa,ya,'k.',xb,yb,'b.',xc,yc,'g.',xd,yd,'c.',LineWidth=3)
        hold on
        axis equal
        line_plot1 = plot([xa,xb(ii)], [ya,yb(ii)], 'b',LineWidth=3);
        line_plot2 = plot([xb(ii),xc(ii)], [yb(ii),yc(ii)], 'r',LineWidth=3);
        line_plot3 = plot([xc(ii),xd], [yc(ii),yd], 'm',LineWidth=3);
        line_plot4 = plot([xd,xa], [yd,ya], 'c',LineWidth=3);
        axis equal
        hold off
        pause(0.06)
    else
        continue
    end
end

`

字符串

ukqbszuj

ukqbszuj1#

在迭代15处假定值:
(360* 阿坦(2909776434409463614636144643^(1/2))/16381 -(35869579695136164170619(-(10854241780483^(1/2))/65205930123 - 803672842364/65205930123)^(1/2))/2 - 204158498323266259123683^(1/2)((-(10854241780483^(1/2))/65205930123 - 803672842364/65205930123)^(1/2)/2 -(210944*3^(1/2))/442287 + 1648/147429)+ 11759769043149622934890992/16381)/(23315948147421118318352 *3^(1/2)+ 401972381605023123837879)/pi

  • (360atan(2909776434409463614636144643^(1/2))/16381 +(35869579695136164170619*(-(10854241780483^(1/2))/65205930123 - 803672842364/65205930123)^(1/2))/2 + 204158498323266259123683^(1/2)((2109443^(1/2))/442287 +(-(1085424178048*3^(1/2))/65205930123 - 803672842364/65205930123)^(1/2)/2 - 1648/147429)+ 11759769043149622934890992/16381)/(23315948147421118318
    基本上,solve不会返回一个数字,而是一个表达式,您可以做的是使用vpa对表达式进行数值求解并将其传递给max()
    在solve之后添加以下行应该可以做到这一点:
t31 = vpa(t31)
     t41 = vpa(t41)

字符串
最终代码将是:

a=1.6;
b=2.14;
c=2.06;
d=3.5;
AB=a
BC=b
CD=c
AD=d
xa=0;
ya=0;
yd=0;
xd=AD;
t2=0
syms t3 t4
for ii=1:36


    t2=t2+10
    f=a*cosd(t2) + b*cosd(t3) - c*cosd(t4) -3.5

    g=a*sind(t2) + b*sind(t3) - c*sind(t4)

    [t31, t41]=(solve(f==0,g==0,t3,t4))

    t31 = vpa(t31)
    t41 = vpa(t41)
    
    th3=double((max(t31)))

    th4=double((max(t41)))
    
    if exist('th3', 'var') 
        xb(ii)=AB*cosd(t2);
        yb(ii)=AB*sind(t2);
        xc(ii)=xb(ii)  + BC*cosd(th3)
        yc(ii)=yb(ii)  + BC*sind(th3)
        
        plot(xa,ya,'k.',xb,yb,'b.',xc,yc,'g.',xd,yd,'c.',LineWidth=3)
        hold on
        axis equal
        line_plot1 = plot([xa,xb(ii)], [ya,yb(ii)], 'b',LineWidth=3);
        line_plot2 = plot([xb(ii),xc(ii)], [yb(ii),yc(ii)], 'r',LineWidth=3);
        line_plot3 = plot([xc(ii),xd], [yc(ii),yd], 'm',LineWidth=3);
        line_plot4 = plot([xd,xa], [yd,ya], 'c',LineWidth=3);
        axis equal
        hold off
        pause(0.06)
    else
        continue
    end
end

相关问题