0% found this document useful (0 votes)
105 views12 pages

Nisrina Nadhifah - Tugas 2 Komputasi Geofisika

This document contains 12 problems analyzing output from MATLAB code. The problems cover topics like transposing matrices, element-wise multiplication, plotting functions, and timing code execution. Sample MATLAB code is provided for problems involving operations on vectors and matrices, plotting functions, and timing code running times. The document appears to be homework or practice problems for a class focusing on MATLAB fundamentals.

Uploaded by

Nisrina Nadhifah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views12 pages

Nisrina Nadhifah - Tugas 2 Komputasi Geofisika

This document contains 12 problems analyzing output from MATLAB code. The problems cover topics like transposing matrices, element-wise multiplication, plotting functions, and timing code execution. Sample MATLAB code is provided for problems involving operations on vectors and matrices, plotting functions, and timing code running times. The document appears to be homework or practice problems for a class focusing on MATLAB fundamentals.

Uploaded by

Nisrina Nadhifah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Nama : Nisrina Nadhifah

NPM : 1855051001
Tugas 2 Komputasi Geofisika

Problem 1.2.1. If z = [0 -1 2 4 -2 1 5 3], and J = [5 2 1 6 3 8 4 7], determine what


is produced by the following sequences of Matlab statements:
>> x = z’, A = x*x’, s = x’*x, w = x*J,
>> length(x), length(z)
>> size(A), size(x), size(z), size(s)
Problem 1.3.1. Determine what is produced by the Matlab statements:
>> i = 1:10
>> j = 1:2:11
>> x = 5:-2:-3
Problem 1.3.2. If z = [0 -1 2 4 -2 1 5 3], and J = [5 2 1 6 3 8 4 7], determine what
is produced by the following Matlab statements:
>> z(2:5)
>> z(J)
Problem 1.3.3. Determine what is produced by the following Matlab statements:
>> A = zeros(2,5)
>> B = ones(3)
>> R = rand(3,2)
>> N = randn(3,2)

Problem 1.3.4. Determine what is produced by the Matlab statements:


>> x = linspace(1, 1000, 4)
>> y = logspace(0, 3, 4)
Problem 1.3.5. Given integers a and b, and a rational number h, determine a
formula for n such that linspace(a, b, n) = [a, a+h, a+2h, ..., b]

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

You might also like