我在第7行(隔离)正好有此代码的问题。请有人可以阅读此代码并帮助我解决问题。当我运行我的代码时,他们告诉我第7行中有错误7。
eqn = m*a == -m*g*sin(theta);
syms r
eqn = subs(eqn,a,r*diff(theta,2));
eqn = isolate(eqn,diff(theta,2));
syms omega_0
eqn = subs(eqn,g/r,omega_0^2);
syms x
approx = taylor(sin(x),x,'Order',2);
approx = subs(approx,x,theta(t));
eqnLinear = subs(eqn,sin(theta(t)),approx);
syms theta_0 theta_t0
theta_t = diff(theta);
cond = [theta(0) == theta_0, theta_t(0) == theta_t0];
assume(omega_0,'real')
thetaSol(t) = dsolve(eqnLinear,cond);
gValue = 9.81;
rValue = 1;
omega_0Value = sqrt(gValue/rValue);
T = 2*pi/omega_0Value;
theta_0Value = 0.1*pi; % Solution only valid for small angles.
theta_t0Value = 0; % Initially at rest.
vars = [omega_0 theta_0 theta_t0];
values = [omega_0Value theta_0Value theta_t0Value];
thetaSolPlot = subs(thetaSol,vars,values);
fplot(thetaSolPlot(t*T)/pi, [0 5]);
grid on;
title('Pendulum Motion');
xlabel('t/T');
ylabel('\theta/\pi');
x_pos = sin(thetaSolPlot);
y_pos = -cos(thetaSolPlot);
fanimator(@fplot,x_pos,y_pos,'ko','MarkerFaceColor','k','AnimationRange',[0 5*T]);
hold on;
fanimator(@(t) plot([0 x_pos(t)],[0 y_pos(t)],'k-'),'AnimationRange',[0 5*T]);
fanimator(@(t) text(-0.3,0.3,"Timer: "+num2str(t,2)+" s"),'AnimationRange',[0 5*T]); ```