linearized-pendulum-error plot
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
Sivsankar
le 4 Sep 2024
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.
0 commentaires
Sam Chak
le 4 Sep 2024
Hi @Manuel Hess
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')
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!