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