Question
for this matlab code what is the value of ires at the end of the code?
ires = 0; for index = 10:-2:4 if index == 6 break; end ires = ires + index; end
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

----------------------------------------------------------------------------------------------------------------

             CODE:

ires=0;
for index =10:-2:4
if index==6
break;
end
ires=ires+index;
end
ires

----------------------------------------------------------------------------------------------------------------

SNIPPET:

HNMOCO ires=0; for index -10:-2:4 if index==6 break; end ires=ires+index; end ires

----------------------------------------------------------------------------------------------------------------

OUTPUT:

ires = 18

EXPLANATION:

here we are using for loop from 10 to 4 with stride of 2 . that means index value would be 10 and then 8 and so on..upto 4

in 1st iteration , ires would be 10

in second iteration  , ires would be 10 + 8 = 18

in third iteartion , the value of index would be 6 and it will break the for loop.

thus ires would contain the value as 18

----------------------------------------------------------------------------------------------------------------

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
for this matlab code what is the value of ires at the end of the code?...
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
  • 4. Consider the following code: ires - 0; for indexl - 10:-2:4 for index2 = 2:2:...

    4. Consider the following code: ires - 0; for indexl - 10:-2:4 for index2 = 2:2: indexl if index2 - 6 break end ires = ires + 2; end end Evaluate in the space below the number of times indexl runs, the number of times index2 runs, and the value of ires at the end of the loop. You can verify the ires results from MATLAB but no screenshots are needed. You are required to show all work below to...

  • explain please What is the value of X at the end of this MATLAB code? X=2;...

    explain please What is the value of X at the end of this MATLAB code? X=2; for X = [X, 2*X]; end 2. X= [2 4 6 8] X= [2 4 4 8 4 8 8 16] X= [2 4 6 8 16] X= [2 4 6 4 8] X= [2 4 4 4 8]

  • For the following M ATLAB code, What is the output of this code and many iterations...

    For the following M ATLAB code, What is the output of this code and many iterations will be performed if the Target entered is: Enter your target: 4? Enter your target: 5? Vector = -6:2:8; Target = input ('Enter your target:'). Position =0; for index = 1: length (Vector) if vector (index) == Target Position =Index; break end end if position == 0 disp ('The target was not found') else disp (['Position = ' num2str (Position)]) end

  • MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while'...

    MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while' loops to exit the loop early. Look at the following example code: x=-10; while x<0       x=x+2;      if x == -2             break;       end end Without the break statement, the while loop would usually add 2 to x=-10 until x=0, and then produce a final answer of x=0 at the end of the loop. Now, the loop ends prematurely when the value of...

  • In the MATLAB code below what does the line: A(i) = 0; do? Is A(i) just...

    In the MATLAB code below what does the line: A(i) = 0; do? Is A(i) just a variable or does in index something? P=1000; r=0.01; n=1; f for loop to calculate monthly interest and yearly interest for i=1:10 A(i)=0; for j=1:12 Am=P* (1+r)^n; P=Am; end A(i) = Am; end % display the amount compounded annually for 10 years i=1:10; table=[i', A']; disp('year Amount') fprintf('%2d %6.2f \n', table')

  • I need a working MATLAB CODE for GAUSS SEIDEL ITERATIVE SCHEME the matlab code must compare...

    I need a working MATLAB CODE for GAUSS SEIDEL ITERATIVE SCHEME the matlab code must compare with actual value and break if this condition is not met i will dislike think before answering a correct working matlab code must be given or else i will dislike badly

  • Note: I need matlab code and it must be on first entry, output what the question...

    Note: I need matlab code and it must be on first entry, output what the question needs and i need it without any false in the matlab pls program logic: • Find the index of minimum element with min() function. Make sure to take two outputs while using min(), the second output is the location of the minimum element. • replace the element at minimum index with mean(v) • find sum(v) and assign it to output program: function x =...

  • MATLAB HELP This is currently what has been written. The problem is that pos needs to...

    MATLAB HELP This is currently what has been written. The problem is that pos needs to be answered in a row vector form. Currently it says pos= 1 pos=4 pos=7 pos=8 in the command window when it is run. But, I don't know how to change what is written to make it display as pos = [ 1 4 7 8] instead. How would I change the code to pos to be displayed as [ 1 4 7 8]? vec...

  • Question: Code your own MATLAB program to find the approximate value of the Integeral 0 to...

    Question: Code your own MATLAB program to find the approximate value of the Integeral 0 to 2 ex dx with Trapezoidal rule for N = 20, i.e., t20. Also give the relative error of t20 with Integeral 0 to 2 ex dx = e2 − 1. (Hint: For-end loops or Elementwise operations)

  • MATLAB code. Open loop TF D(s) Matlab Code: a=conv([1 0], [1 1]) b=conv([1 5], [1 10])...

    MATLAB code. Open loop TF D(s) Matlab Code: a=conv([1 0], [1 1]) b=conv([1 5], [1 10]) D=conv(a,b) N=1 sys=tf(N, D) rlocus(sys) roots([4 16*3 65*2 50]) OUTPUT Matlab: a = 1 1 0 b = 1 15 50 D = 1 16 65 50 0 N = 1 sys = 1 ---------------------------- s^4 + 16 s^3 + 65 s^2 + 50 s Continuous-time transfer function. ans = -8.2399 -3.3005 -0.4596 Question: How to change this code to closed loop TF with:...

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