Question

Instructions: For your lab write-up follow the instructions of LAB 1 1. (a) Modify the function exvith2eqs to solve the IVP (
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Programing code:

%1.
%a)
%Solve the Differential Equation using ODE45
tspan = [0 35];
y0 = [0 0.01];
[t, Y] = ode45(@(t, y) f(t, y), tspan, y0);

%Plot the results
figure;
plot(t, Y(:,1), 'k', t, Y(:, 2), 'r');

%Add limits to the plot
ylim([-1.5, 1.5]);
xlim([0 35]);
grid on;

%Add legends
legend('y = y(t)', "v=v(t)=y'(t)");

%Plot the phase
figure;
plot(Y(:, 1), Y(:, 2));
grid on;

%Add limits tot he phase plot
ylim([-1.5, 1.5]);
xlim([-1, 1]);

%Add labels to the phase plot
xlabel('y'); ylabel("v = y'");

%b)
fprintf("At %f and %f of t, y reachees a local maximum of %f and %f respectively.", 2.5773, 4.2284, 0.0002, 0.0004);
%Define the function f
function dYdt = f(t, Y)


OUT PUT:

Figure2 File Edit View Insert Tools Desktop Window Help 1.5 0.5 0.5 1.5 -1 0.6 0.4 0.2 0.2 0.4 06 08 01:14 O Type here to seaFigure File Edit View nsert Tools Desktop Window Help 1.5 0.5 0.5 1.5 10 15 20 25 30 35 O Type here to search e脚 rP ^ 4x ENG

%d)

%1.
%a)
%Solve the Differential Equation using ODE45
tspan = [0 35];
y0 = [5 7];
[t, Y] = ode45(@(t, y) f(t, y), tspan, y0);

%Plot the results
figure;
plot(t, Y(:,1), 'k', t, Y(:, 2), 'r');

%Add limits to the plot
ylim([-1.5, 1.5]);
xlim([0 35]);
grid on;

%Add legends
legend('y = y(t)', "v=v(t)=y'(t)");

%Plot the phase
figure;
plot(Y(:, 1), Y(:, 2));
grid on;

%Add limits tot he phase plot
ylim([-1.5, 1.5]);
xlim([-1, 1]);

%Add labels to the phase plot
xlabel('y'); ylabel("v = y'");

%b)
fprintf("At %f and %f of t, y reachees a local maximum of %f and %f respectively.", 2.5773, 4.2284, 0.0002, 0.0004);
%Define the function f
function dYdt = f(t, Y)
y = Y(1); v = Y(2);
dYdt = [v; 2*cos(t)-6*v-4*y];
end


OUT PUT:

● Figure 2 Fle Edit View nsert Icos Desktop Window Help 0.5 0.5 1.5 -1 0.8 0.6 0.4 0.2 0.2 0.4 0.6 08 01:22 O Type here to seFigure Fle Edit View nsert Icos Desktop Window Help 1.5 y-Xo 0.5 0.5 1.5 10 15 20 25 30 35 O Type here to search e脚 rP ^ 4x Ey = Y(1); v = Y(2);
dYdt = [v; 2*cos(t)-6*v-4*y];
end

Add a comment
Know the answer?
Add Answer to:
Instructions: For your lab write-up follow the instructions of LAB 1 1. (a) Modify the function e...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c...

    t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c = .6; d = .1; [t,y] = ode45(@f,[t0,tf],y0,[],a,b,c,d); u1 = y(:,1); u2 = y(:,2); % y in output has 2 columns corresponding to u1 and u2 figure(1); subplot(2,1,1); plot(t,u1,'b-+'); ylabel('u1'); subplot(2,1,2); plot(t,u2,'ro-'); ylabel('u2'); figure(2) plot(u1,u2); axis square; xlabel('u_1'); ylabel('u_2'); % plot the phase plot %---------------------------------------------------------------------- function dydt = f(t,y,a,b,c,d) u1 = y(1); u2 = y(2); dydt = [ a*u1-b*u1*u2 ; -c*u2+d*u1*u2 ]; end Only...

  • help me with this. Im done with task 1 and on the way to do task...

    help me with this. Im done with task 1 and on the way to do task 2. but I don't know how to do it. I attach 2 file function of rksys and ode45 ( the first is rksys and second is ode 45) . thank for your help Consider the spring-mass damper that can be used to model many dynamic systems -- ----- ------- m Applying Newton's Second Law to a free-body diagram of the mass m yields the...

  • f(T) = 22 9 Instructions: • If you are asked for a function, enter a function....

    f(T) = 22 9 Instructions: • If you are asked for a function, enter a function. • If you are asked to find 2- or y-values, enter either a number or a list of numbers separated by commas. If there are no solutions, enter None. • If you are asked to find an interval or union of intervals, use interval notation. Enter { } if an interval is empty • If you are asked to find a limit, enter either...

  • PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a...

    PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a Python program that displays and describes the equation for plotting the sine function, then prompts the user for the values A, B, C and D to be used in the calculation. Your program should then compute and display the values for Amplitude, Range, Frequency, Phase and Offset. Example input/output for part 1: Part 2: Displaying a Vertical Plot Header A vertical plot of the...

  • MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...

    MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...

  • 2. The energy of the mass-spring system is given by the sum of the kinetic energy and the potenti...

    using matlab help to answer #2 please show steps in creating code 2. The energy of the mass-spring system is given by the sum of the kinetic energy and the potential energy. In the absence of damping, the energy is conserved (a) Add commands to LAB05ex1 to compute and plot the quantity E-m k2 as a function of time. What do you observe? (pay close attention to the y-axis scale and, if necessary, use ylim to get a better graph)....

  • write MATLAB scripts to solve differential equations. Computing 1: ELE1053 Project 3E:Solving Differential Equations Project Principle...

    write MATLAB scripts to solve differential equations. Computing 1: ELE1053 Project 3E:Solving Differential Equations Project Principle Objective: Write MATLAB scripts to solve differential equations. Implementation: MatLab is an ideal environment for solving differential equations. Differential equations are a vital tool used by engineers to model, study and make predictions about the behavior of complex systems. It not only allows you to solve complex equations and systems of equations it also allows you to easily present the solutions in graphical form....

  • 1. Consider the circuit shown below. Cl e, (0) c, e。(t) Find the transfer function below using t...

    Please help with this dynamics circuit analysis. Please show work and explain. Thank you!! 1. Consider the circuit shown below. Cl e, (0) c, e。(t) Find the transfer function below using time-domain and impedance methods. (a) Determine the differential equation for the relationship between eo(1) and e(1) (b) Find the transfer function E, (s)/E,(s) and determine the system time constant in terms of the circuit element values C, C, and R 17 2 (c) Find the transfer function E, (s)/E,...

  • PLEASE HELP SOLVE WITH MATLAB LANGUGE. Below are hints to the problem. THANKS A LOT!! 2...

    PLEASE HELP SOLVE WITH MATLAB LANGUGE. Below are hints to the problem. THANKS A LOT!! 2 Coriolis Force In a rotating frame-of-reference,the equations of motion of a particle, written in co- ordinates fixed to the frame, have additional terms due to the rotation of the frame itself Consider such a rotating frame, with its origin at the center of rotation.In these coor- dinates, the equations of motion for a point-mass subjected to forces F, and F S m, are F(0...

  • (b) . Write the k-th step of the trapezoidal method as a root-finding problem Ğ = is Y+1 where the unknown (e)Find the Jacobian matrix of the vector function from the previous part. (dWrite a funct...

    (b) . Write the k-th step of the trapezoidal method as a root-finding problem Ğ = is Y+1 where the unknown (e)Find the Jacobian matrix of the vector function from the previous part. (dWrite a function in its own file with definition [Y] dampedPendulum(L, T) function alpha, beta, d, h, that approximates the solution to the equivalent system you derived in part (a) with L: the length of the pendulum string alpha: the initial displacement beta: the initial velocity d:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT