Love: Function and X= Essay

Submitted By ko78
Words: 337
Pages: 2

Exercise 3.1:
a) >> f = inline('x^2 - 1', 'x', 'y')

f =

Inline function: f(x,y) = x^2 - 1

>> h= 0.25

h =

0.2500

ans =

0 1.0000 0.5000 0.5000 1.0000 0.1250 1.5000 0.1250 2.0000 0.7500

For h= 0.25, the estimate of y when x= 1 is 0.1250. Also, the estimate of y when x= 2 is 0.7500.
For h= 0.1, the estimate of y when x= 1 is 0.2850. And the estimate of y when x= 2 is 1.4700.
For h= 0.01, the estimate of y when x= 1 is 0.3284. And the estimate of y when x= 2 is 1.6467.

b)

c) As h decreases, Euler’s estimate appears to give better estimates because the estimates of y get smaller and closer to one another as h decreases. Also, the curve is also smoother, so it gives better estimates. Euler’s estimate appears to give worse estimates as I move farther from the initial points.

Exercise 3.2:
>> x = zeros(10,1); y = zeros(10,1);
[x,y]

ans =

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0

Exercise 3.3 :

a)

As h decreases, the accuracy of the graph increases. The graph with h=0.1 has a smooth curve compared to other graphs. As a result, the x and y coordinates are closer to another. Therefore, the coordinates and the graph are more accurate as h decreases.

b)

Yes, I believe that as h decreases, the graph will change significantly. The graph has a smoother curve. For each step size, there would be a more accurate curve and it depends on the number of h.

Exercise 3.4:

a)
>> g = inline('-cos(x)+2')
[x,y,g(x),abs(y-g(x))]

g =

Inline function: g(x) = -cos(x)+2

ans =

0 1.0000 1.0000 0 0.2500 1.0311 1.0311 0.0000 0.5000 1.1224 1.1224 0.0000 0.7500 1.2683 1.2683 0.0000 1.0000 1.4597 1.4597 0.0000 1.2500 1.6848 1.6847 0.0001 1.5000 1.9293 1.9293 0.0000 1.7500 2.1782 2.1782 0.0001 2.0000 2.4161 2.4161 0.0000 2.2500 2.6282 2.6282 0.0001 2.5000 2.8012 2.8011 0.0000 2.7500 2.9243 2.9243 0.0000 3.0000 2.9900 2.9900 0.0000 3.2500 2.9941 2.9941 0.0000 3.5000 2.9365 2.9365 0.0000 3.7500 2.8206 2.8206 0.0000 4.0000 2.6536 2.6536 0.0000 4.2500 2.4460 2.4461 0.0001 4.5000 2.2108 2.2108 0.0000 4.7500 1.9625 1.9624 0.0001 5.0000 1.7163 1.7163 0.0000 5.2500 1.4879 1.4879 0.0001 5.5000 1.2913 1.2913 0.0000 5.7500 1.1388 1.1388 0.0000 6.0000 1.0398 1.0398 0.0000 6.2500 1.0006 1.0006 0.0000 6.5000 1.0234 1.0234 0.0000 6.7500 1.1070 1.1070 0.0000 7.0000 1.2461 1.2461 0.0000 7.2500 1.4321 1.4321 0.0001 7.5000 1.6534 1.6534 0.0000 7.7500 1.8961 1.8962 0.0001 8.0000 2.1455 2.1455 0.0000 8.2500 2.3858 2.3857 0.0001 8.5000 2.6020 2.6020 0.0000 8.7500 2.7808 2.7808 0.0000 9.0000 2.9111 2.9111 0.0000 9.2500 2.9848 2.9848 0.0000 9.5000 2.9972 2.9972 0.0000 9.7500 2.9476 2.9476 0.0000 10.0000 2.8391 2.8391 0.0000

The values of column 2nd and 3rd are almost the same. However, there is a 0.0001 difference between the estimate of the ode45 value and the exact function value.

b)
>> f = inline('sin(x)', 'x', 'y');

[x, z] = Euler(0.25, 0, 1, 10, f);

[y, z, g(x), abs(y - g(x)), abs(z - g(x))]

ans =

Columns 1 through 4

1.0000 1.0000 1.0000 0 1.0311 1.0000…