Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a working matlab code - % Parameters M = 1 ; K = 3 ; B = 0 . 5 ; x 0

I have a working matlab code -% Parameters
M =1;
K =3;
B =0.5;
x0=2;
v0=0;
t0=0;
tend =15;
h =0.01;
% Function for Euler equation solution
f1= @(t, x1, x2) x2;
f2= @(t, x1, x2)-(B/M)* x2-(K/M)* x1;
% Euler method
tn_euler = t0:h:tend;
x1_euler = zeros(size(tn_euler));
x2_euler = zeros(size(tn_euler));
x1_euler(1)= x0;
x2_euler(1)= v0;
fprintf('All Euler steps
');
for i =1:length(tn_euler)-1
t = tn_euler(i);
x1= x1_euler(i);
x2= x2_euler(i);
x1_euler(i+1)= x1+ h * f1(t, x1, x2);
x2_euler(i+1)= x2+ h * f2(t, x1, x2);
fprintf('%f %f %f
', tn_euler(i), x1_euler(i), x2_euler(i));
end
% Plotting numerical solution using Euler method
figure;
hold on;
plot(tn_euler, x1_euler, 'linewidth', 2);
plot(tn_euler, x2_euler, 'linewidth', 2);
plot(tn_euler, -0.5* x2_euler -3* x1_euler, 'linewidth', 2);
legend('Displacement', 'Velocity', 'Acceleration');
title('Solution using Euler method');
box on;
% Runge-Kutta 4 method
x1_rk4= zeros(size(tn_euler));
x2_rk4= zeros(size(tn_euler));
x1_rk4(1)= x0;
x2_rk4(1)= v0;
fprintf('All Runge Kutta 4 steps
');
for i =1:length(tn_euler)-1
t = tn_euler(i);
x1= x1_rk4(i);
x2= x2_rk4(i);
k1= h * f1(t, x1, x2);
l1= h * f2(t, x1, x2);
k2= h * f1(t + h/2, x1+ k1/2, x2+ l1/2);
l2= h * f2(t + h/2, x1+ k1/2, x2+ l1/2);
k3= h * f1(t + h/2, x1+ k2/2, x2+ l2/2);
l3= h * f2(t + h/2, x1+ k2/2, x2+ l2/2);
k4= h * f1(t + h, x1+ k3, x2+ l3);
l4= h * f2(t + h, x1+ k3, x2+ l3);
x1_rk4(i+1)= x1+(k1+2*k2+2*k3+ k4)/6;
x2_rk4(i+1)= x2+(l1+2*l2+2*l3+ l4)/6;
fprintf('%f %f %f
', tn_euler(i), x1_rk4(i), x2_rk4(i));
end
% Plotting numerical solution using Runge-Kutta 4 method
figure;
hold on;
ylim([-6,6]);
plot(tn_euler, x1_rk4, 'linewidth', 2);
plot(tn_euler, x2_rk4, 'linewidth', 2);
plot(tn_euler, -0.5* x2_rk4-3* x1_rk4, 'linewidth', 2);
legend('Displacement', 'Velocity', 'Acceleration');
title('Solution using Runge-Kutta 4 method');
box on; And I need to implement this to it, Turn off the sliding friction and set h =0.1, but keep all other parameters the same.
Integrate using the Euler Method. You will see that the oscillator is now unstable.
As one shrinks h, the oscillations become more convergent to steady state, however,
ideal behavior (y(t)= y(t + T), where T is the period of the oscillation) requires
infinite numerical precision.
Show what the behavior looks like with the IEM and the RK4 method for h =0.1
[DLV x 2].
Find the limit of h for the Euler Method (EM) such that the oscillations increase by
less than 1% over a period of 1 oscillation, i.e., y(t + T)<=1.01* y(t)[DLV].
For part II, you may have to change the Integration_Time to examine the stability.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago