Using Matlab 1. Solve the following without the use of for/while loops. The solu
ID: 3736362 • Letter: U
Question
Using Matlab
1. Solve the following without the use of for/while loops. The solution should not be entered manually but as a result of an algorithm. The following vector and matrix are provided: V- 3:4:133; M- [0 2 0; 8030 0 5]. (a) Add 3 to the non-zero elements of M that are also smaller than 5; (b) Add 2 to all elements of V that are divisible by 7; (c) Return a numeric vector of all elements of V containing the digit 7; and (d) Prompt a user for two numbers and create a vector vl of length 30 with equal spacing, starting with the given numbers. Create a new vector v2 containing the sums of every two consecutive elements of v1 (e.g., if given vector is v1-1,2,3,4,.., the new sequence should be v2-3,5,7,...) (20 marks)Explanation / Answer
V=3:4:133;
M=[0 2 0;8 0 3;0 0 5];
%a
M(M~=0&M<5)=M(M~=0&M<5)+3;
%b
V(mod(V,7)==0)=V(mod(V,7)==0)+2;
%c
%checking unit digit of all numbers
ind1=find(mod(V,10)==7);
%ones digit of 2 digit numbers
ind2=find(floor(V/10)==7&V<100);
%since V goes till 133,the 3 digit numbers will have 7 only at unit digits, which we have checked
Numbers=V([ind1 ind2]);
%d
a=input('Enter number 1: ');
b=input('Enter number 2: ');
v1=linspace(a,b,30);
v2=v1(1:end-1)+v1(2:end);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.