Question

In: Computer Science

the question should be done on Matlab. There is a vector defined as H = [-88,...

the question should be done on Matlab.

There is a vector defined as H = [-88, 45, 75, 24, 14, 19, -11, 9, -5, -3, 12, 19 ,56, -4, 5,

17, -6, -8, -9, 6, 15]

Write a program as a script file that triples the elements that are positive and a divisible by 3 or 5, and, raises to the power of 2 the elements that are negative but greater than -11.

Solutions

Expert Solution

Code:

H = [-88, 45, 75, 24, 14, 19, -11, 9, -5, -3, 12, 19 ,56,...
    -4, 5,17, -6, -8, -9, 6, 15];
n = size(H); % [ 1 x ] where x = no. of elements in H
n = n(2); % n= x

for i = 1:n % loop through elements of H
    if(H(i)>0) % if element is greater than 0
        % and divisible by 3 or 5 
        if((mod(H(i),3)==0)||(mod(H(i),5)==0))
            % then triple it
            H(i)=H(i)*3;
        end
    elseif(H(i)<0) % if element is less than 0
        % if greater than -11
        if(H(i)>-11)
            % raise it to the power of 2
            H(i)=2^(H(i));
        end
    end
end
disp(H);

Screenshot:

Code output

==================

Comments have been added by the side of each line to help you understand better.

Please upvote.

For any query comment.


Related Solutions

question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8...
question should be done on Matlab 4) Find the derivative of sin(2x) at x = 0.8 rad and find the value of h where the error is minimum as compared to the true value i.e. actual value or accurate value. a) Use for loop b) Use element by element operation
i need to do piano in matlab . its keys number should ve 88 and i...
i need to do piano in matlab . its keys number should ve 88 and i need a source . Can u help ne ?
MATLAB Given a 20x20 matrix named G and a 20x1 vector named H, multiply the elements...
MATLAB Given a 20x20 matrix named G and a 20x1 vector named H, multiply the elements in the 14th column of G by the values in H (element-by-element multiplication, not a multiplication table).
In this question we study the recursively defined functions f, g and h given by the...
In this question we study the recursively defined functions f, g and h given by the following defining equations f(0) = −1 base case 0, f(1) = 0 base case 1, and f(n) = n · f(n − 1) + f(n − 2)^2 recursive case for n ≥ 2. and g(0, m, r, k) = m base case 0, and g(n, m, r, k) = g(n − 1, r,(k + 2)r + m^2 , k + 1) recursive case for...
In this question we study the recursively defined functions f, g and h given by the...
In this question we study the recursively defined functions f, g and h given by the following defining equations f(0) = −1 base case 0, f(1) = 0 base case 1, and f(n) = n · f(n − 1) + f(n − 2)^2 recursive case for n ≥ 2. and g(0, m, r, k) = m base case 0, and g(n, m, r, k) = g(n − 1, r,(k + 2)r + m^2 , k + 1) recursive case for...
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
Use Matlab to introduce arow vector,f,and define it as a 1 by 4 vector showing values...
Use Matlab to introduce arow vector,f,and define it as a 1 by 4 vector showing values of 1, 2, 3and 4. Now try to build matrix D, using the following 2 commands a.D = [f ; A] b.D= [f , A] c.Which one can be built,and which one cannot be built? Explain your answer. Matrix A, which is a 4by 4 matrix, (The first, second, third and fourth column values are:2,4,6,8and 1,3,5,7 and 8,6,4,2 and 7,5,3,1 , respectively.
MATLAB. A three vector force system has forces as outlined, use a three element vector to...
MATLAB. A three vector force system has forces as outlined, use a three element vector to represent the x, y, and z terms respectively, F = [x_value, y_value, z_value]. Find the resultant force when: F1 has a magnitude of 120 N and is in the x-y plane, 35 degrees BELOW the positive x axis, F2 has a magnitude of 810 N and is in the x-z plane, 100 degrees ABOVE the positive x axis, and F3 has a magnitude of...
Please Use the STL library for this question and Should be done in C++ and Provide...
Please Use the STL library for this question and Should be done in C++ and Provide screenshots of the OUTPUT Topic: Stack Infix to postfix conversion         Take Input mathematical expression in infix notation, and convert it into a postfix notation. The infix notation may or may not have round parenthesis. Postfix expression evaluation         Take Input mathematical expression in postfix form, evaluate it, and display the result The mathematical expression can contain Numbers as operands (numbers can be of...
QUESTION: USING MATLAB, Carry out three iterations of the Gauss-Seidel method, starting from the initial vector...
QUESTION: USING MATLAB, Carry out three iterations of the Gauss-Seidel method, starting from the initial vector Use the  ,  and  norm to calculate the residual error after each iteration, until all errors are below 0.0001. [Use 5 decimal place accuracy in you calculations]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT