Homework 1 WRTE MATLAB CODES FOR EACH QUESTONS 1 Create an

Homework 1 (WRTE MATLAB CODES FOR EACH QUESTONS ?)
1) Create an array with randomly-selected 1000 elements between -50 and 50. Find the minimum number in the array. Calculate its absolute value. Calculate modulus of absolute value after divided by 7 and equate this value to a variable named “number1” Find the maximum number of the array. Take its absolute value. Take modulus of absolute value after divided by 13 and equate this value to a variable named “number2” Compare “number1” and “number2”. Create a variable “result” such that; If number1 is greater than or equal to number2, result is half of the length of the array. If number1 is less than number2, result is 2 times of the length of the array. Write the corresponding matlab code for the question. (May the force be with you...)
2) Create an array with randomly-selected 1000 elements between -50 and 50. Compare each element of the array such that; If the element is greater than 30; change it as 30. If the element is less than -30; change it as -30. If the element is between -30 and 30; the element keeps its value. Write the corresponding matlab code for the question.
3)
Define a 1001-by-8 matrix, named “A”, whose elements selected randomly.
Define an 8-by-1001 matrix, named “B”, whose elements selected randomly.
Define a variable “C” as the multiplication of matrices “A” and “B”.
Define a variable “D” as the mean value of the first column of “C”.
Write the necessary matlab code in script format.
4) Assume that you have a data set of voltage and current values of a circuit element. Voltage and current values are stored in separate arrays v and i. These values are measured with respect to time data created in section a.
a) Generate a time vector t that starts from 0 to 10 sec with 0.01 sec increments. Shift this vector +2 and -2 sec.
b) Create a new variable named x, and equate it to the size of time vector, defined in section a by using the size function.
c) Create voltage and current vectors with rand function that are same sized with the time vector defined in section a.
d) Plot time versus voltage and time versus current graphs.
e) Define a function that takes the voltage, and current as input and gives the instantaneous power as output.
f) Calculate and the instantaneous power.
g) Calculate average power.

Solution

prob2)

a=-50;b=50;
r = a + (b-a).*rand(1000,1);
for i=1:1:length(r);
if (r(i)<30)
if(r(i)>-30)
r(i)=r(i);
else
r(i)=-30;
end
else
r(i)=30;
end

end

3)

clear all;
A=rand(1001,8);
B=rand(8,1001);
C=A*B;
D=mean(C(:,1));

Homework 1 (WRTE MATLAB CODES FOR EACH QUESTONS ?) 1) Create an array with randomly-selected 1000 elements between -50 and 50. Find the minimum number in the ar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site