Question

In: Mechanical Engineering

Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...

Write and upload a MATLAB script to do the following.

Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1;

(a)    Case 1, Assume K = 1

(b)    Case 2, Assume K = 2

(c)     Case 3, Assume K = 4

Plot all of these on the same plot, for N = 1 to 20

Solutions

Expert Solution

k=1;

for n=3:1:22
s(3)=0;
s(4)=1;
s(n)=((2-k).*s(n-1))-s(n-2);
s(3)=0;
s(4)=1;
end
for i=1:1:20
    x(i)=s(i+2)
end
n=[1:1:20];
plot(n,x)
hold all
k=2;

for n=3:1:22
s(3)=0;
s(4)=1;
s(n)=((2-k).*s(n-1))-s(n-2);
s(3)=0;
s(4)=1;
end
for i=1:1:20
    y(i)=s(i+2)
end
n=[1:1:20];
plot(n,y)
hold all

k=4

for n=3:1:22
s(3)=0;
s(4)=1;
s(n)=((2-k).*s(n-1))-s(n-2);
s(3)=0;
s(4)=1;
end
for i=1:1:20
    z(i)=s(i+2)
end
n=[1:1:20];
plot(n,z)


Related Solutions

Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n. 2. C= A*B where A is of dimension m by p and B is dimension of p by n. So write matlab script to obtain Y and C in above problems.
MATLAB, if-else Write a script which to do the following. Take an array of any size...
MATLAB, if-else Write a script which to do the following. Take an array of any size as input and check if all the elements are integers. (i) If not, display the error message ‘Invalid input!’. Use the error command to create a proper error message in red. (ii) If yes, count the number of rows where the sum of the elements is smaller than the average row sum. It is recommended that you use a test variable with many rows...
Write a Matlab m-script to compute the backward difference approximation A = f(a)−f(a−h) h of the...
Write a Matlab m-script to compute the backward difference approximation A = f(a)−f(a−h) h of the derivative T = f0(a) for f(x) = sin(x) and a = π/3 using each value of h in the sequence 2−n (n = 1,2,3,···,52).
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all...
Use Matlab and write entier script Problem 1. Using the information above, find y(n) for all n between 1:N. y(tn)=mx(tn)+b+r(tn) y=mx+b Plot the points on a graph, without connecting them with a line.   Use a command like: plot( x, y, ‘.r’ ) Now we want to find the “best fit” solution.   As was mentioned before, this was defined in the prior exercise. (You may wish to read this to understand how the algorithm works.)   Use the MATLAB code below. You...
write matlab script of N channel MOSFET (Iv curve) will like and comment if done correctly...
write matlab script of N channel MOSFET (Iv curve) will like and comment if done correctly plesse
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this...
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this part, write your own script). Consider x=-0.5 to 3 with Δt=0.01, and compare your result with using “integral” and "trapz" commands (all in one file).
#2 The Jacobsthal sequence is defined by J(1)=J(2)=1 and J(n)=J(n-1)+2J(n-2). Use recursion to write a function...
#2 The Jacobsthal sequence is defined by J(1)=J(2)=1 and J(n)=J(n-1)+2J(n-2). Use recursion to write a function that takes in a positive integer n and returns the nth Jacobsthal number. >>> J(8) 85 >>> J(9) 171 #3 Use recursion to write a function that takes in a positive integer n and returns all n digit numbers containing only odd digits. >>> f(1) [1, 3, 5, 7, 9] >>> f(2) [11, 13, 15, 17, 19, 31, 33, 35, 37, 39, 51, 53,...
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
Use Matlab and write entier script Problem 2. Generate the estimate (linear estimate) for y_est, and...
Use Matlab and write entier script Problem 2. Generate the estimate (linear estimate) for y_est, and plot(x , y_est). Use “hold on” and plot(x,y) and plot(x,y_est), so that you can see the result of the line and how it fits the data.   Does it look like it did a pretty good job? An estimate of the “residual error” is the sum of the squares of the difference between y and y_est. This is often denoted as r2. r2 = sum(...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT