In the previous example, the values f(3) and [f(1), f(2), f(3)] were displayed i
ID: 3403348 • Letter: I
Question
In the previous example, the values f(3) and [f(1), f(2), f(3)] were displayed in the command window using the numeric format we specified in preferences. Sometimes we want more control over the format, so we use the fprintf command (section 1 of the Overview). As an example, f = @(x) x.^2+1; x = .6221; fprintf(’f(%6.5f) = %12.4e ’,x,f(x)) fprintf(’f(%6.5f) = %12.4e ’,3.706,f(3.706)) Note that changing the output display does not change the value stored in MATLAB. Your assignment is to print the values of f(x) = sin(x 3 ) at the points x = 5.201, 8323.6, 0.0003 twice, in floating point (f format) with 8 digits after the decimal and then in scientific notation (e format) with 10 digits after the decimal. Check the help page (type helpwin fprintf) for details. Notice that the floating point format is not appropriate for the third x; get in the habit of printing in scientific notation to see the magnitude of a number.
Explanation / Answer
given f(x) = sin (x 3)
at x = 5.201 we have f(5.201) = sin ( 5.201 * 3) = 0.1047
at x= -8323.6 f(-8323.6) = sin (-8323.6* 3) = - 0.9888.
at x= 0.0003 f(-0.0003) = sin ( -0.0003 * 3 ) = -000089
matlab program is like this
for x= 5.201, 8323.6, 0.0003
x= linespace(-2,2,10)
y = sin (x 3);
plot (x,y,'r');
axis [ -2,2,8,.8]
x label ['x'];
y label ['Y'];
grid
pause(3)
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.