% MAT 362 MATLAB Assignment #1
% Armando Luquin
% Exercise #1
format compact
theta = [0, pi/4, pi/2, 3*pi/4, pi, 5*pi/4];
r = 2;
x = r*cos(theta);
y = r*sin(theta);
r_calc = sqrt(x.^2 + y.^2)
r_calc =
2
2
2
2
2
2
% Exercise #2
% Part A)
t = linspace(1, 10, 91);
y = (exp(t/10) .* sin(t)) ./ (t.^2 + 1);
figure
plot(t, y, 'k', 'Linewidth', 1.5)
grid on
xlabel('t')
ylabel('y(t)')
% Part B)
figure
plot(t, y, 'o')
xlabel('t')
ylabel('y(t)')
figure
plot(t, y, 'o-')
grid on
xlabel('t')
ylabel('y(t)')
# Exercise 3
t = linspace(0, 20, 1000);
x = sin(t);
y = cos(t);
z = t;
plot3(x,y,z)
% Exercise 4
x = linspace(0, pi, 1000);
y=cos(x);
z = 1- x.^2 /2 + x.^4 /24;
plot(x,y,'r',x,z,'--')
grid on
% Exercise 5
function ex5
x = linspace(0,4,400);
y1 = f(x,-1);
y2 = f(x,0);
y3 = f(x,1);
plot(x,y1,'-',x,y2,'--',x,y3,':')
title('Solutions to dy/dx = x + 2')
legend('C = -1','C = 0','C = 1','Location','northwest')
grid on
end
function y = f(x,C)
y = x.^2/2 + 2*x + C;
end
% Exercise 6
f = @(x,y) x.^3 + y.*exp(x) ./(x+1);
f(2, -1)
ans =
5.5370
clear f
function out = f(x,y)
out = x.^3 + y.*exp(x) ./(x+1);
end
f(2, -1)
ans =
5.5370
diary off