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...
3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a...
3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a function to quickly compute this sequence. >>> [hc(i) for i in range(1,20)] [1, 1, 2, 2, 3, 4, 4, 4, 5, 6, 7, 7, 8, 8, 8, 8, 9, 10, 11]
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).
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
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).
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
#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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT