Question

In: Advanced Math

MATLAB question! 4. (a) Modify the code, to compute and plot the quantity E = 1/2mv^2...

MATLAB question!

4. (a) Modify the code, to compute and plot the quantity E = 1/2mv^2 + 1/2ky^2 as a function of time. What do you observe? Is the energy conserved in this case?

(b) Show analytically that dE/dt < 0 for c > 0 while dE/dt > 0 for c < 0.

(c) Modify the code to plot v vs y (phase plot). Comment on the behavior of the curve in the context of the motion of the spring. Does the graph ever get close to the origin? Why or why not?

given code
---------------------------------------------------------------

clear all;   
m = 4; % mass [kg]
k = 9; % spring constant [N/m]
c = 4; % friction coefficient [Ns/m]
omega0 = sqrt(k/m); p = c/(2*m);
y0 =-0.8; v0 = 0.3; % initial conditions
[t,Y] = ode45(@f,[0,15],[y0,v0],[],omega0, p); % solve for 0<t<15
y = Y(:,1); v = Y(:,2); % retrieve y, v from Y
figure(1); plot(t,y,'ro-',t,v,'b+-');% time series for y and v
grid on; axis tight;
%---------------------------------------------------
function dYdt = f(t,Y,omega0,p); % function defining the DE
y = Y(1); v = Y(2);
dYdt=[ v ; -omega0^2*y-2*p*v]; % fill-in dv/dt
end

-----------------------------------------------------------------------------------------

Solutions

Expert Solution


clear all;
m = 4; % mass [kg]
k = 9; % spring constant [N/m]
c = 4; % friction coefficient [Ns/m]
omega0 = sqrt(k/m); p = c/(2*m);
y0 =-0.8; v0 = 0.3; % initial conditions
[t,Y] = ode45(@f,[0,15],[y0,v0],[],omega0, p); % solve for 0<t<15
y = Y(:,1); v = Y(:,2); % retrieve y, v from Y
figure(1); plot(t,y,'ro-',t,v,'b+-');% time series for y and v
title('y(t) and v(t) plot')
xlabel('time (t)')
ylabel('y(t) and v(t) plot')
grid on; axis tight;

%Answering question 4a.
E=((1/2).*m.*v.^2)+((1/2).*k.*y.^2);
figure(2); plot(t,E,'ro-');% time series for E
title(sprintf('E(t) vs. time plot for c=%d',c))
xlabel('time (t)')
ylabel('E(t) plot')
grid on; axis tight;

%Answering question 4a.

figure(5); plot(y,v,'ro-');% time series for E
title(sprintf('Phase space plot for c=%d',c))
xlabel('y(t)')
ylabel('v(t)')
grid on; axis tight;


%Answering question 4b.
E=((1/2).*m.*v.^2)+((1/2).*k.*y.^2);
figure(3); plot(t,E,'ro-');% time series for E
title('E(t) vs. time plot for c>0')
xlabel('time (t)')
ylabel('E(t) plot')

grid on; axis tight;
m = 4; % mass [kg]
k = 9; % spring constant [N/m]
c = -4; % friction coefficient [Ns/m]
omega0 = sqrt(k/m); p = c/(2*m);
y0 =-0.8; v0 = 0.3; % initial conditions
[t,Y] = ode45(@f,[0,15],[y0,v0],[],omega0, p); % solve for 0<t<15
y = Y(:,1); v = Y(:,2); % retrieve y, v from Y

E=((1/2).*m.*v.^2)+((1/2).*k.*y.^2);
figure(4); plot(t,E,'bo-');% time series for E
title('E(t) vs. time plot for c<0')
xlabel('time (t)')
ylabel('E(t) plot')
grid on; axis tight;

fprintf('\nFor question 4a)\n')
fprintf('\tFrom the energy plot it can be shown that the energy is decreasing gradually and E conserved.\n')
fprintf('Due to friction energy is dissipated.\n')

fprintf('\nFor question 4b)\n')
fprintf('\tFor C>0 Energy gradually decreases so dE/dt<0.\n')
fprintf('\tFor C<0 Energy gradually decreases so dE/dt>0.\n')

fprintf('\nFor question 4b)\n')
fprintf('\tFrom phase plot, graph get close to origin\n')
fprintf('As velocity decreases and energy dissipates it gets close to origin.\n\n')
%---------------------------------------------------
function dYdt = f(t,Y,omega0,p) % function defining the DE
y = Y(1); v = Y(2);
dYdt=[ v ; -omega0^2*y-2*p*v]; % fill-in dv/dt
end


%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%


Related Solutions

Modify the sum_thread.cpp program to compute sum = 1 + 1/2 + 1/3 + 1/4 +...
Modify the sum_thread.cpp program to compute sum = 1 + 1/2 + 1/3 + 1/4 + … 1/n. Let’s estimate natural using n = 20. sum_thread.cpp #include <chrono> #include <iostream> #include <mutex> #include <random> #include <utility> #include <vector> #include <thread> using namespace std; constexpr long long size= 1000000; mutex myMutex; void sumUp(unsigned long long& sum, const vector<int>& val, unsigned long long beg, unsigned long long end){ long long localSum = 0; for (auto it= beg; it < end; ++it){ localSum+=...
use a matlab built-in function to numerically solve: dy/dx= -x^2+((x^3*e^-y)/4) for 1<=x<=5 with y(1)=1 plot the...
use a matlab built-in function to numerically solve: dy/dx= -x^2+((x^3*e^-y)/4) for 1<=x<=5 with y(1)=1 plot the solution
This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in...
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in the response. C1 : x=−5+2e−tcos20t y=−5+2e−tsin20t z=4t C2 : x=−5+2e−tcos20t y=5+2e−tsin20t z=4t C3 : x=5+2e−tcos20t y=−5+2e−tsin20t z=4t C4 : x=5+2e−tcos20t y=5+2e−tsin20t z=4t
MATLAB CODE: A particular 3x3 linear transformation A has eigenvalues of -1, 2, and 4, and...
MATLAB CODE: A particular 3x3 linear transformation A has eigenvalues of -1, 2, and 4, and corresponding eigenvectors with directions of [1;1;0], [0;1;l], and [1;1;1], respectively. Because eigenvectors must have unit length, you will need to normalize the given vectors by the length of each array to find the actual eigenvectors. Given this information, and using the eigen decomposition, find the linear transformation A. Hint: you can use the diag() function to form the D matrix from the provided eigenvalues....
Could you modify the code make output arranged into 5x5, like this: 1 2 3 4...
Could you modify the code make output arranged into 5x5, like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 The code is: import java.util.*; public class RandomGen { public static void main(String[] args) { int[][] ArrayRand = new int [5][5]; Random rand = new Random(); int sum = 0; System.out.println("The generated random matris is: ");    for(int i = 0; i <...
Question 1 Problem 2.64 Use MATLAB to solve for and plot the response of the following...
Question 1 Problem 2.64 Use MATLAB to solve for and plot the response of the following models for 0≤t ≤1.5, where the input is f (t) =5t and the initial conditions are zero: 3¨ x +21˙ x +30x = f (t) A)  Use math (analytically) to find the response of the models given in Problem 2.64 of your book. Show all assumptions and all steps of your derivation. (Turn in the calculations.) B) Use MATLAB to solve the same problem 2.64...
c++ question Question 2: X = 7777 Modify the code below and use conditional branching (if,...
c++ question Question 2: X = 7777 Modify the code below and use conditional branching (if, else, etc.) to print the following: if X is between 0 and 33333 then print the word: red if X is between 33334 and 66666 then print the word: blue if X is between 66667 and 99999 then print the word: green if none of the above condition matches then print the word: white
Question 5. Use MATLAB to solve for and plot the response of the following models for...
Question 5. Use MATLAB to solve for and plot the response of the following models for 0≤t ≤1.5, where the input is f (t) =5t and the initial conditions are zero a. 3¨ x +21˙ x +30x = f (t) b. 5¨ A (Turn in the MATLAB script and answers from MATLAB, .m file, screen shots if needed) B (Turn in the MATLAB plot with t being time in SI units) C Comment on the response the analytical solution compared...
using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n]...
using matlab, compute and plot y [n] = x [n]* h [n], where a. x [n] = h [n] = a^n (0 <=n <=40) & a = 0.5 b. x [n] = cos [n]; h [n] = u [n]; n = 0:4:360 c. x [n] = sin [n] ; h [n] = a^n; n:4:360; a = 0.9
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT