伊莉討論區

標題: [matlab]使用int函氏來積分 [打印本頁]

作者: ericwu830701    時間: 2016-6-15 04:38 PM     標題: [matlab]使用int函氏來積分

close all;
figure
hold on
syms t_o;
d_t=0.01;
x=0;
for t=0:d_t:1
    x_d_dot=pi*cos(pi*t/2)/2;
    y=-20*x+(pi/2);
    f=-(1.5+0.5*sin(t_o))*y^2*cos(3*x);
    s=(y-x_d_dot+20*(x-sin(pi*t/2)));
    if(s >= 0)
        g=1;
    else g=-1;
    end

    u=1.5*(y)^2*cos(3*x)-pi^2*sin(pi*t_o/2)/4-20*(y-x_d_dot)-(0.5*y^2*abs(cos(3*x))+0.1)*g;
%   u1=1.5*(y)^2*cos(3*x)-pi^2*sin(pi*t/2)/4-20*(y-x_d_dot)-(0.5*y^2*abs(cos(3*x))+0.1)*g;
    x=x+double(int(int(f+u,t_o),t_o,t,t+d_t));
    plot(t,u);
end
axis([0 5 -5 6])

在這中想要畫出u的圖形,但在plot(t,u)中卻跑出錯誤Conversion to double from sym is not possible.
請問各位大大這要怎麼解決


作者: a778899447    時間: 2016-6-17 10:20 AM

在plot(t,u)之前加 double(u)就可以把sym型態轉回double了




歡迎光臨 伊莉討論區 (http://www.web01.eyny.com/) Powered by Discuz!