Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use a for loop to fill in an array ! 1 solution submitted (max: 10) View my solutions One of the most common applications of

image text in transcribed
image text in transcribed
image text in transcribed
Use a for loop to fill in an array ! 1 solution submitted (max: 10) View my solutions One of the most common applications of for loops in MATH 307 is to fill in the entries of an array one at a time. * = (x(1), (2), (3), . xD)... X()); Create an array x of size 1000 where the entry of the array is computed by the previous entry mutiplied by 3 and then added to 1. That is, *.1 = 3x + 1 The first entry should start at 2, that is x1 = 2. Need more practice with this? Here are some free resources: . Matlab Onramp, do section 13.3: https://www.mathworks.com/learn/utorials/matlab-onramp.html . Tutorials Point: https://www.tutorialspoint.com/matlab/matlab_loops.htm - Office hours-- you're always welcome. Script 1 % initialize the array as zeros 2 x = zeros (1,1080); 4 * fill in the first entry (doesn't follow the pattern) 5 6 7 % use a for loop to fill in the rest of the entries (that follow the pattern) B for is 9 x(i) = 10 end Fibonacci O solutions submitted (max: 10) Write a script file that delines a number n and creates an array called fib containing the first n terms of the Fibonacci sequence (1.1.2.3.5.8.13...) After the first two is, the patter is the next number is the sum of the previous two. Need more practice with this? Here are some free resources: Matlab Onramp, do section 13.3: https://www.mathworks.com/learn/tutorials/matlab-onramp.html . TutorialsPoint: https://www.tutorialspoint.com/matfablmatlab_loops him Office hours- you're always welcome. ok Script 1 = 100; 2 Usen to create fib 4 7 function w fibonacci(varargin) X fprintf('This program uses the function fibonacci, which is not allowed to be used for this homework assignment. In'); 9 end 10 Use a for loop to compute a sum I O solutions submitted (max: 10) One of the most common applications of for loops in MATH 307 is to compute a sum: si start Compute the sum using a for loop. Store the result in the variable mysum. 278 i? - sin(i) 7=3 224 + 1 Need more practice with this? Here are some free resources: . Matlab Onramp, do section 13.3: https://www.mathworks.com/learn/tutorials/matlab-onramp.html TutorialsPoint: https://www.tutorialspoint.com/matlab/matlab_loops.htm - Office hours-- you're always welcome. Script 1 % start by initializing mysum 2 mysum 3 4 % now use a for loop to compute mysum 5 for i = % fill in the range of indices 6 mysum = mysum + % add the next term to mysum 7 end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

Students also viewed these Databases questions