Question

For each of the below codes, determine if the following MATLAB codes produces an error. • If the code does NOT produce an err
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. The first code does not product any error.

OUTPUT:

B=

-1, 8, 4 , 34, 18, 52

octave:2> A= [1,5,2,9,4,9]; octave:3> B(1,5)=0; octave: 4> counter=1; octave:5> for i= 1: length(A) > > B(i)=A(i)*counter; >

Explanation:

A= 1, 5, 2 , 9, 4, 9

B= 0, 0, 0, 0, 0

counter=1

for i = 1 to length(A) i.e.,

i = 1 to 6

  • i = 1
  • B(1) = A(1)*counter =1
  • B(1)=1-2= -1
  • counter=counter+1 =2

Now i=2

  • B(2)= A(2)*counter = 5*2= 10
  • B(2)= B(2)-2 =10-2= 8
  • Counter=counter+1 =2+1 =3

Hence the loop executes till the value of i is equal to 10 and the value of counter increases by 1 everytime for loop block is executed.

Hence counter=1

2. Code produces error:

The error is : A;

; is undefined symbol.

To output the value of A.. it should be simply written A and not A;

So it does not output anything.

octave:2> A=[1]; octave:3> B=[3]; octave: 4> C=[5,4,3,2,1,0]; octave:5> for i=1:length(C) > > A(i+1)=B(i)-mod(B(i),3); > > B(

3. The code is not able to add A+B

Because final matrix A has different dimension i.e., size( 6*5)

And Matrix B has different dimension i.e., size(6*6)

Therefore it is not possible to execute:

C=A+B

octave:2> A=ones (5,5); octave:3> Brzeros(6,6); octave: 4> for n=1:5 > > A(6,n)=2; > > end octave:5> C=A+B error: operator +:Final values of A and B

octave:5> А А = 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 octave: 6> B В = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

A and B cannot be added.

4. The code does not produce any error. It works fine.

The output is:

Counter=11

octave:2 A(1)=3 A = 3 octave: 3> B(1)=5 B = 5 octave: 4> counter=1 counter = 1 octave:5> for i=1:10 > > A(counter+1)=mod(i,A(

Add a comment
Know the answer?
Add Answer to:
For each of the below codes, determine if the following MATLAB codes produces an error. •...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For each of the below codes, determine if the following MATLAB codes produces an error. If...

    For each of the below codes, determine if the following MATLAB codes produces an error. If the code does NOT produce an error, predict the output. If the code DOES produce an error: (1) state what line the FIRST error is found and (2) what the error is clear;clc %ICE08B-1 A = [1,5,2,9,4,9]; B(1,5) = 0; counter = 1; for i = 1:length(A)     B(i) = A(i) * counter;     B(i) = B(i)-2;     counter = counter + 1; end

  • Exercise 11 (2 pts.): When the following Matlab program is run, it produces an error. WHERE...

    Exercise 11 (2 pts.): When the following Matlab program is run, it produces an error. WHERE in the Matlab program does the error occur (underline the specific line of Matlab code that produces the error), and WHY does it occur? cleariclc A[-1, 0, -2, 3, 4, 61 Exercise 12 (2 pts.): When the following Matlab program is run, it produces an error. WHERE in the Matlab program does the error occur (underline the specific line of Matlab code that produces...

  • I want to see the work written out because I do not understand how a for...

    I want to see the work written out because I do not understand how a for loop works without running it on MatLab Exercise 13 (2 pts.): Predict the output that appears in Matlab's command window when the following Matlab program is run (REMEMBER to SHOW SOME WORK!) clear;clc a = 3; c=2; d = zeros (1,5) -2; for m - 1:5 x = (m-1)"c; y = (-1)^n; z=x-y; d(m) = z + 1; end

  • For each of the following Matlab codes, fill in each cell of the empty template with TWO VALUES: ...

    For each of the following Matlab codes, fill in each cell of the empty template with TWO VALUES: (1) A NUMERICAL VALUE that appears in that cell of the matrix; and (2) A WORD identifying the COLOR that appears in that cell, as a result of the matrix being interpreted as an image using Matlab's IMAGESC command. Examples: "Red", "Green", "Cyan", etc. DO NOT PUT THE MATLAB RGB COLOR CODE IN THE CELL! That is, instead of the word "Red",...

  • In each of the below syntax exercises, determine the output that results from running the specified...

    In each of the below syntax exercises, determine the output that results from running the specified MATLAB program.  If there is no output because an error results, write “ERROR” and then explain why the error occurs. clear; clc a = 3; b = 2; c = 1; for m = 1:3 for n = 1:3 if n < m      a = b - c elseif n == m b = a + 1; else c = 2*b + a; end end...

  • I need the code written in Matlab software to send a number of bits using the...

    I need the code written in Matlab software to send a number of bits using the Pulse Shape Modulation, and demodulate the signal using the correlation coefficient. The part that i need to modified is the part that is in Bold. The two functions are : function [outSignals,time] = modulation(inBits) and function [outBits] = demodulation(inSignals). %% Main Function function runComm_code()     clear;clc;   SNRdB = 0:0.5:26;     nBits = 1e6;     SNRdBLength = length(SNRdB);     Pe = ones(1,SNRdBLength);     clc; disp('Simulation...

  • clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j=...

    clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j= i:N if (mod(i,j)==0) d = d+1; fprintf('%d\t \n',i); end    end end How can I determine the Positive PRIME factors only out of this code? What should I debug? (MATLAB)

  • Complete the Logic section of the below MATLAB code to detect the pattern shown where a...

    Complete the Logic section of the below MATLAB code to detect the pattern shown where a single pixel/element is EITHER RED or GREEN question you will need to fill in the two upper limits of the for loops and write out the IF statement RED or GREEN CDS-130 Final Exam clear: clc counter = 0; Lor X = 1: 15 for y - 1:15 A (x,y) = randi (4)-1; end end mycolormap = [ 1; 1 ; 10 0; 1...

  • Using MATLAB please. A = rand(m,n) x = rand(n,1) b = A * x 1. What...

    Using MATLAB please. A = rand(m,n) x = rand(n,1) b = A * x 1. What does the following code compute? Explain what operation the third line is per- forming b = zeros(m, 1); for i = 1:m b(i) = A(i,:) * x; end Make a copy of the relevant MATLAB function you wrote earlier, and use this code in place of the two loops you wrote. Time both codes on a sufficiently large problem. Which performs faster?

  • Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noi...

    Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noise=5*sin(2*50*3.*t); refer=5*sin(2*50*3.*t+ 3/20); primary=desired+noise; subplot(4,1,1); plot(t,desired); ylabel('desired'); subplot(4,1,2); plot(t,refer); ylabel('refer'); subplot(4,1,3); plot(t,primary); ylabel('primary'); order=2; mu=0.005; n=length(primary) delayed=zeros(1,order); adap=zeros(1,order); cancelled=zeros(1,n); for k=1:n, delayed(1)=refer(k); y=delayed*adap'; cancelled(k)=primary(k)-y; adap = adap + 2*mu*cancelled(k) .* delayed; delayed(2:order)=delayed(1:order-1); end subplot(4,1,4); plot(t,cancelled); ylabel('cancelled');

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT