{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ME218LAB3

# ME218LAB3 - Greg Gangluff gg2593 Lab 3 3.1 The value of y...

This preview shows pages 1–4. Sign up to view the full content.

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' );

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

View Full Document
3.4 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 plot(x,F) xlabel( 'Input' ); ylabel( 'Force' ); title( 'Forces' ); 3.6 if ( x == 12 & x == -3) (commands)
End 3.7 Code: response = 1; total=0; while (response ~= 0) beep disp( 'Well hello there!' ) response = input(

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}