linearized​-pendulum-​error plot

1 次查看(过去 30 天)
Manuel Hess
Manuel Hess 2020-3-25
回答: Sam Chak 2024-9-4
Hello,
is there somebody who has an matlab file which plots the error between a linearized equation and a nonlinear equation over the angle of a pendulum?
I am not smart enough to solve this task and I couldnt find something like this in the file exchange.
Tanks for your help
Manuel

回答(2 个)

Sivsankar
Sivsankar 2024-9-4
Hi Manuel,
You can refer to the following MATLAB answer which provides MATLAB functions for linear and nonlinear pendulum:
You can find the error by subtracting between the two pendulums and then plot it using the plot function. You can leverage the following documentation on ‘plot’ to get an idea on how to plot the error:
Thanks.

Sam Chak
Sam Chak 2024-9-4
It's late, but here is how you can make the comparison.
% Parameters
g = 9.80665; % standard acceleration of gravity
l = g; % length of pendulum
% Linear model
linpen = @(t, x) [x(2); - 2*x(2) - g/l*x(1)];
% Nonlinear model
nonpen = @(t, x) [x(2); - 2*x(2) - g/l*sin(x(1))];
% Solver settings
tspan = [0, 10];
x0 = [deg2rad(80); 0]; % initial condition (try setting to 30 deg)
% Plot results
[t, xL] = ode45(linpen, tspan, x0);
plot(t, rad2deg(xL(:,1))), hold on
[t, xN] = ode45(nonpen, tspan, x0);
plot(t, rad2deg(xN(:,1))), grid on, xlabel('t / sec'), ylabel('\theta / deg')
legend('Linear model', 'Nonlinear model')

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by