0% found this document useful (0 votes)
31 views

Lab 1

This document contains the output and code from 10 exercises in a MATLAB assignment. The exercises cover topics such as logarithms, vectors, plotting functions, solving differential equations, and taking derivatives of symbolic expressions. For each exercise, the relevant code and output is shown.

Uploaded by

Zandra Rojo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lab 1

This document contains the output and code from 10 exercises in a MATLAB assignment. The exercises cover topics such as logarithms, vectors, plotting functions, solving differential equations, and taking derivatives of symbolic expressions. For each exercise, the relevant code and output is shown.

Uploaded by

Zandra Rojo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MATLAB Assignment 1

Exercise 1.1
Output:
>>log(20)/log(8)
ans =
1.4406
Exercise 1.2
Comment:
Inputting m= -3:0.4:12 will create a row vector ranging from -3 to 12 in increments of 0.4.
Typing in m(26) will output the 26th element of the vector m.
Output:
>> m(26)
ans=
7
Exercise 1.3
Output:
>> z = 25-(100-7exp(5+cos(pi/3))
z = 25-(100-7exp(5+cos(pi/3))
Error: Unexpected MATLAB operator.
>> z = 25-(100-7*exp(5+cos(pi/3)))
z=
1.6378e+03
Exercise 1.4
Output:
>> g = inline('sin(x)/(x)')
>> fplot(g, [-10,10])

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-10

Exercise 1.5
Code:
(a)
r= 1/3;
a=1;
for i=0:6
x= a*r^i
end

(b)
geomSeq.m
for i=0:6
x= a*r^i
end

(c)
function geomSeq(r)
a=1;
for i=0:6
x= a*r^i
end
end

Output:

-8

-6

-4

-2

10

(a)
x=
1
x=
0.3333
x=
0.1111
x=
0.0370
x=
0.0123
x=
0.0041
x=
0.0014
(c)
>> geomSeq(1/4)
x=
1
x=
0.2500
x=
0.0625
x=
0.0156
x=
0.0039
x=
9.7656e-04
x=
2.4414e-04
Exercise 1.6
Code:
(a)
function sum=mysum(r, n)
sum= 0;
for i=0:n
sum=sum+ 1/r^n;
end

end

Output:
>> mysum(3,12)
ans =
2.4462e-05

Exercise 1.7

Output:
>> dsolve('Dy=sin(t)')
ans =
C10 - cos(t)
>> dsolve('Dy=sin(t)', 'y(0)=3')
ans =
4 - cos(t)
Exercise 1.8
Output:
>> dsolve('Dy=(y-sin(y))')
Warning: Explicit solution could not be found; implicit
solution returned.
> In dsolve at 201
ans =
solve(y - sin(y) == 0, y)
solve(int(1/(y - sin(y)), y, IgnoreAnalyticConstraints) - t - C55 == 0, y)
Exercise 1.9
Output:
>> syms s t
>> g=log(sin(s)+cos(t))
g=

log(cos(t) + sin(s))
>> diff(g, 't')
ans =
-sin(t)/(cos(t) + sin(s))
>> diff(g, 's')
ans =
cos(s)/(cos(t) + sin(s))
Exercise 1.10
Output:
>> asin(1)
ans =
1.5708

You might also like