Question

In: Computer Science

Mathlab Q1. Instruction Text % For loop code: vec = [45, -1, 7, 0, -37, 4,...

Mathlab

Q1. Instruction Text

% For loop code:

vec = [45, -1, 7, 0, -37, 4, -3];

newvec = zeros(1,numel(vec)); % pre-allocate newvec with zeros

for idx = 1:numel(vec)

if vec(idx) > 1 & vec(idx) < 0

numerator = 3*vec(idx)^3;

denominator = 9*vec(idx)^2 + 3;

else

numerator = 2*vec(idx)^3 - 2*vec(idx);

denominator = 2*vec(idx)^2 - 2/vec(idx);

end

newvec(idx) = numerator/denominator;

end

Solutions

Expert Solution

clc;

vec = [45, -1, 7, 0, -37, 4, -3]; %Initialize vector with values

newvec = zeros(1,numel(vec)); % pre-allocate newvec with zeros

% For loop code:

for idx = 1:numel(vec) %iterate through each value in vec

if vec(idx) > 1 & vec(idx) < 0

numerator = 3*vec(idx)^3;

denominator = 9*vec(idx)^2 + 3;

else

numerator = 2*vec(idx)^3 - 2*vec(idx);

denominator = 2*vec(idx)^2 - 2/vec(idx);

end

newvec(idx) = numerator/denominator;

end


Related Solutions

hat does the code below do? clear vec = randi(20,1,100)-10; iter=0; k=1; while k<= length(vec) if...
hat does the code below do? clear vec = randi(20,1,100)-10; iter=0; k=1; while k<= length(vec) if vec(k)<0 vec(k)= vec(k) * -1; end k = k+1; end a. This code generates a vector with 100 random integer elements between 20 and 100, and changes the sign of the elements coverting all poivitive ones to negative and all negative ones to positive. b. This code generates a vector with 20 random integer elements between 1 and 100, and changes the sign of...
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1...
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1 0 2 11 5 11 27 4 0 6 Create Standard Deviation Chart (Normal Distribution Curve)
MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slt
MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slti $t1, $s0, 7                   beq $t1, $zero, exit                   addi $s0,$s0,1                   j loop exit:                   add $v0, $zero, $s0                   jr $ra       What is the corresponding high-level programming language code? Write a code in your preferred language. What is the result? (5 pts) Code: int add(int a, int b) {       return a+b; } int sub(int a, int b) {      ...
True and False 1. The instruction register stores machine code for the instruction being executed. 2....
True and False 1. The instruction register stores machine code for the instruction being executed. 2. Before a digital computer may execute an instruction, the instruction code must be fetched from memory. 3. A pointer is a binary code for data in the arithmetic logic unit. 4. Von Neumann computer architecture stores data and instruction codes in the same memory. 5. Complex instruction set computers have instructions with greater speed than those in reduced instruction set computers.
A= 1 0 -7 7 0 1 0 0 2 -2 10 -7 2 -2 2...
A= 1 0 -7 7 0 1 0 0 2 -2 10 -7 2 -2 2 1 Diagonalize the matrix above. That is, find matrix D and a nonsingular matrix P such that A = PDP-1 . Use the representation to find the entries of An as a function of n.
(9) Diagonalizing 4 0 1 -7 -5 5. -12 -6 7
(9) Diagonalizing 4 0 1 -7 -5 5. -12 -6 7
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
Mother's age 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,51 Female 1, 0, 2, 2, 3, 4, 7, 3, 2, 4, 7, 1,...
Mother's age 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,51 Female 1, 0, 2, 2, 3, 4, 7, 3, 2, 4, 7, 1, 6, 4, 5, 3, 1, 4, 0, 1, 1, 1, 0, 1, 0 Use the stem and leaf plots that you previously created to help you draw and label histograms on your scratch paper with bin width of 2 for mothers's age at birth of female students and for mother's age at birth of male students. Make the lower bound of your first bin...
Updated! Python Code 4. Enhanced transmission method Use the same probabilities ?0 ; ?0; and ?1...
Updated! Python Code 4. Enhanced transmission method Use the same probabilities ?0 ; ?0; and ?1 as before and consider the following experiment: p0=0.6 ; e0=0.05; e1=0.03 • You create and transmit a one-bit message S as before. In order to improve reliability, the same bit “S” is transmitted three times (S S S) as shown in Figure 2. • The received bits “R” are not necessarily the same as the transmitted bits “S” due to transmission errors. The three...
Where is the infinite loop in the code? Input for the code 1 2.5 2 40200000...
Where is the infinite loop in the code? Input for the code 1 2.5 2 40200000 1 0 2 80400000 2 ffffffff 3 #include <stdio.h> #include <math.h> #include <stdlib.h> int count = 31; void toBinary(int num, int n){ for(int i = 1; i < n; i++){ if((int)(num/pow(2,(n-i))) > 0){ num = num - pow(2,(n-i)); printf("1"); count--; }else{ printf("0"); count--; } } } char checkSign (int sign) { char new_sign; if (sign == 0) { new_sign = '+'; return new_sign; }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT