Nisrina Nadhifah - Tugas 2 Komputasi Geofisika
Nisrina Nadhifah - Tugas 2 Komputasi Geofisika
Nisrina Nadhifah - Tugas 2 Komputasi Geofisika
NPM : 1855051001
Tugas 2 Komputasi Geofisika
Problem 1.3.6. Write Matlab code that evaluates and plots the functions:
(a) y = 5 cos(3πx) for 101 equally spaced points on the interval 0 ≤ x ≤ 1.
(b) y = 1 1 + x 2 for 101 equally spaced points on the interval −5 ≤ x ≤ 5.
(c) y = sin 7x − sin 5x cos 7x + cos 5x using 200 equally spaced points on the
interval −π/2 ≤ x ≤ π/2. Use the axis command to scale the plot so that −2 ≤ x ≤ 2
and −10 ≤ y ≤ 10.
(a)
(b)
(C)
Problem 1.3.7. A “fixed–point” of a function g(x) is a point x that satisfies x =
g(x). An “educated guess’ of the location of a fixed–point can be obtained by
plotting y = g(x) and y = x on the same axes, and estimating the location of the
intersection point. Use this technique to estimate the location of a fixed–point for
g(x) = cos x.
Problem 1.3.8. Use Matlab to recreate the plot in Fig. 1.4. Hints: You will need
the commands hold, xlabel, ylabel, and legend. The ± symbol in the legend can be
created using \pm.
Problem 1.3.9. Explain what happens when the following Matlab code is
executed.
for k = 1:6
x = linspace(0, 4*pi, 2^(k+1)+1);
subplot(2,3,k), plot(x, sin(x))
axis([0, 4*pi, -1.5, 1.5])
end
Problem 1.3.10. Write a function M–file, PlotCircles.m, that accepts as input a
vector, r, having positive entries, and plots circles of radius r(i) centered at the
origin on the same axes. If no input value for r is specified, the default is to plot a
single circle with radius r = 1. Test your function with r = 1:5. Hint: Matlab
commands that might be useful include max, min and any.
Problem 1.3.11. The Matlab functions tic and toc can be used to find the (wall
clock) time it takes to run a piece of code. For example, consider the following
Matlab statements:
f = @(x) 1 ./ (1 + x.*x);
tic
for i = 1:n
x = rand(n,1);
y = f(x);
end
toc
Problem 1.3.12. Repeat the experiment in Problem 1.3.11, but this time use
e x + sin πx
f(x) = 2
x +7 x +4