Question

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

end

a

b

c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output from the results of running specified matlab program is :

a = -7
a =  13
a =  13
a =  13
b =  14
c = -19

In outer loop m takes values 1 ,2 ,3 and in inner for loop n takes values from 1 , 2, 3

m = 1 , 2 , 3

n = 1 , 2 , 3

value of a is displayed when n<m which occurs three times for following combinations of n,m

{n,m} = {1,2} , { 1 , 3 } , { 2, 3 }

For these three case we arrive at first three answers of solutions which are

a = -7

a = 13

a = 13

and last three parts are diplayed as a result of end computation of results which are

a = 13

b = 14

c = -19

Add a comment
Know the answer?
Add Answer to:
In each of the below syntax exercises, determine the output that results from running the specified...
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. •...

    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 what the error is ICE08B-1: clear;clc SICE08B-1 A = [1,5,2,9,4,9]; B(1,5) = 0; counter = 1; for i = 1:length(A) B(1) = A(i) * counter; B(1) = B(i)-2; counter = counter + 1; end ICE08B-2:...

  • 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 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

  • (a) A cantilever beam shown in Figure 6 is subjected to a concentrated load P. Deflection...

    (a) A cantilever beam shown in Figure 6 is subjected to a concentrated load P. Deflection of the beam at each point can be defined by the following equations: 6EI Pa 6EI F3x-a) for axx<l The following MATLAB code calculates and plots the deflection diagram for a beam with 1-4 m, d1 = 3 m, b = 1 m,E>210 x 10, Pa, 1 = 285 x 10-6 m4 and P = 20 kN. Find at least FOUR errors in the...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

  • 7). What is the resuit of running the foloving code for exth of the ov cases?...

    7). What is the resuit of running the foloving code for exth of the ov cases? ¡f 0 < x < 10 y=4"X y 10*x y- 500 elseif 10 <x <40 else end a, x =-1 y=? c. x- 30 y? 8). Write code to create an M-by-N array of random numbers (use rand Move through the array, element by element, and set any value that is than 0.2 to 0 and any value that is greater than (or equal...

  • Matlab Exercise #1 Syntax of MATLAB The Problem-Solving Tool for Engineers, High-Performance Nu...

    Matlab Exercise #1 Syntax of MATLAB The Problem-Solving Tool for Engineers, High-Performance Numeric Computation and Very Powerful, Very Easy to Use MATLAB Mathematicians, and Scientists Visualization Software Matlab Prompt: ">>" or"o" General Syntax of Matlab [output1, output2, ..]command_name(input1, input2, ...) » % (everything to its right on that line is ignored and is not executed) >> diary filename » diary off % close the diary >>save filename >> save filename xyz %(save variables x, y, and z to file) >>save...

  • Exercises • Determine running time for the following code fragments: (a) a = b + c;...

    Exercises • Determine running time for the following code fragments: (a) a = b + c; d = a + e; (b) sum = 0; for (i=0; i<3; i++) for (j=0; j<n; j++) sum++; (c) sum=0; for (i=0; i<n<n; i++) sum++; (d) for (i=0; i < n-1; i++) for (j=i+1; j <n; j++) { tmp = A[i][j]; A[i][j] = A[j] [i]; A[j][i] = tmp; (e) sum = 0; for (i=1; i<=n; i++) for (j=1; j<=n; j+=2) sum++;

  • Use MATLAB program to answer the following questions. Copy the MATLAB code and the results from running the code 6. Find...

    Use MATLAB program to answer the following questions. Copy the MATLAB code and the results from running the code 6. Find the determinant and inverse of the following 4 x 4 matrix 3 5 -2 6 2-1 A=11 6. Find the determinant and inverse of the following 4 x 4 matrix 3 5 -2 6 2-1 A=11

  • Make this program using MATLAB AND SHOW THE DETAIL WORKING n2 if n 10 2. Let f(n)3n2 2 if 10 n < 30 4n if n 2 30 Crea...

    Make this program using MATLAB AND SHOW THE DETAIL WORKING n2 if n 10 2. Let f(n)3n2 2 if 10 n < 30 4n if n 2 30 Create an m-fhle with a program to find the sum 50 Σ f(n). n=1 Hint: You may find the following commands to be useful: for elseif else end if When you are done, run your program and write the value of the sum here: 50 f(n) Even if you do not manage...

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