ME218LAB3 - Greg Gangluff gg2593 2/12/08 Lab 3 3.1 The...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Greg Gangluff gg2593 2/12/08 Lab 3 3.1 The value of y is 1000, and in each term y is multiplied by e^n/1000, to give the correct value for e^(n) power. y = 1.0e+003 * 0.0027 0.0074 0.0201 0.0546 0.1484 0.4034 1.0966 2.9810 8.1031 3.2 The example does not work because the number is not a integer. So, the easiest way around this problem is to define x as all the values in the loop and use some other variable (like i) as the counting variable. 3.3 Code, graph attached(m-file) x=1:.05:5 for i=1:length(x) y(i) = cos(x(i)) end plot(x,y) xlabel( 'Input' ); ylabel( 'Output' ); title( 'Graph of cos(x) from 1 to 5 with a step of .05' );
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To produce vector A without any for loops, you need to create a 4x1 matrix with the terms [1;10;100;1000] and multiply it by the vector [ 1 3 5 7 9] to get the same output as the for loop. 3.5 Code, Graph attached x=1:20; for i=1:length(x) if ( x(i) < 0 ) Force = 0 ; elseif (0 < x(i) < 10 ) Force = 10*x(i) ; else ( x(i) >=10) Force = 100 ; end F(i)= Force; end
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/23/2011 for the course ME 218 taught by Professor Unknown during the Fall '08 term at University of Texas at Austin.

Page1 / 5

ME218LAB3 - Greg Gangluff gg2593 2/12/08 Lab 3 3.1 The...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online