linearized-pendulum-error plot
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
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.
0 件のコメント
Sam Chak
2024 年 9 月 4 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!