Here is the code for you:
fprintf('\n\n#2\n');
clear all
%A vector x, containing valuews between 0 and 5 is generated randomly.
%The length of x is also dtermined at random.
x = round(5*rand(1, 5+round(5*rand)));
disp(x);
%Set up a for loop to run over all elements of x.
for i = 1 : length(x)
%Inside the for loop use a switch construct to find the odd values:
switch(mod(x(i), 2))
case 1
%Inside the case for the odd values, use an if so that if a 3,
%or 5 is found, that value is replaced by its square.
if x(i) == 3 || x(i) == 5
x(i) = x(i) * x(i);
end
case 0
%Inside the case for even values, use an if so that a 4 is
%found, that value is replaced by its square root.
if x(i) == 4
x(i) = sqrt(4);
end
end
end
disp(x);
And the output screenshot is:
Matlab problem A vector, x, containing values between 0 and 5 is generated randomly below. %...
Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () function, create a script that generates a row vector (1 row X 20 columns) of random numbers, each with magnitude between 0 and 5 b) (3 pts) Use the round() function to turn all of the values into whole numbers by rounding down (truncate the decimal part on your vector) c) (5 pts) Add code to your script to generate a new vector...
matlap Question 1 1. Consider the following Matlab program 5 - (2 < 3) & (C2 > 3) 1 (1 - 0)) What is the final value of s? A. True B. *1 CO D. false 2- Which expression tests whether variable x is between (but not the same as) the values 5 and 10 (a) 5 <x< 10 (b) 5 <= x <= 10 (c) 5 < X & X > 10 (d) x < 10 & 5 <...
Solve in MATLAB Problem 3: Given the vector x- [2 1 0 6 2 3 5 3 4 1 3 2 10 12 4 2 7 9 2 4 51 use a for loop to (a) Add up the values of all elements in x (b) Compute the cumulative sum, y, of elements in x You can check your results using the built-in functions sum and cumsum. Q.5 What is the value of the sum of elements in vector x?...
MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is defined as the square root of n rounded to the nearest integer. Adapting Heron's method to integer arithmetic allows the rounded-square-root of n to be calculated as follows. Let d be the number of digits of number n d-1 If d is odd, then Xo = 2 × 107- If d is even, then Xo-7 × 107- where xo is the starting guess for...
I need this program in MATLAB with different or another code. INPUT: x = [0 1 8 12 27]; y = [1 2 3 4 5]; nx = length(x); ny = length(y); n = length(x); if nx ~= ny display('Error. La cantidad de datos en x no es igual que los datos en y') end Sx = sum(x); Sxx = sum(x.^2); Sy = sum(y); Sxy = sum(x.*y); a1 = (n*Sxy - Sx*Sy)/(n*Sxx-(Sx)^2); a0 = (Sxx*Sy - Sxy*Sx)/(n*Sxx - (Sx)^2); m...
SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...
S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...
Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...
2. (a) We want to find the root x of the function f(x); that is, we need f(r) = 0 . This can be done using Newton's method, making use of the iterative formula f(xn) Show that the sequence ofiterates (%) converges quadratically if f'(x) 0 in some appropriate interval of x-values near the root χ 9 point b) We can get Newton's method to find the k-th root of some number a by making it solve the non-linear cquation...
1. (a) We need to calculate accurate values of the function for very large values of x. However, it is found that just programming this formula into a computer gives very poor accuracy for large x Explain why this happens, and show how to re-write the function so that it can be used reliably, even when x is large. [6 points] (b) In diffraction theory, it is sometimes necessary to evaluate the function sin θ f(x) for small to moderate...