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 Center および File ExchangeGraphics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by