0% found this document useful (0 votes)
156 views6 pages

Mat 275 Matlab Assignment #1

This document contains code for 6 exercises using MATLAB. Exercise 1 generates x and y coordinates to plot a circle based on radius and theta values. Exercise 2 plots a function of t with different line styles. Exercise 3 plots a 3D circular helix. Exercise 4 plots 2 functions of x on the same graph with different styles. Exercise 5 plots solutions to a differential equation with different constants. Exercise 6 defines and evaluates functions.

Uploaded by

Patrick Hayes
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)
156 views6 pages

Mat 275 Matlab Assignment #1

This document contains code for 6 exercises using MATLAB. Exercise 1 generates x and y coordinates to plot a circle based on radius and theta values. Exercise 2 plots a function of t with different line styles. Exercise 3 plots a 3D circular helix. Exercise 4 plots 2 functions of x on the same graph with different styles. Exercise 5 plots solutions to a differential equation with different constants. Exercise 6 defines and evaluates functions.

Uploaded by

Patrick Hayes
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/ 6

Patrick Hayes MWF 7:30-8:20

% MAT 275 MATLAB Assignment #1

% Exercise 1

theta= [ 0 pi/2 pi/4 3*pi/4 pi 5*pi/4]; % values for theta expressed


as a vector
r=2; % value of r(radius) given
x= r*cos(theta); % x as function of r and theta
y= r*sin(theta); % y as a function of r and theta
r1= sqrt(x.^2+y.^2) % this is the proof for the scenario that x and y
form an equation of a circle
% Because r1 is a matrix of 2, the equations x= rcos(theta) and y=
rsin(theta) satisfies the equation of a circle
format compact

% Exercise 2

t2= linspace(1,10,91); % t values for exercise 2


y2=(exp(t2/10) .* sin(t2))./(t2.^2 + 1); % y as a function of t
% Plotting (t,y2) as a curve with a black line
plot(t2,y2,'k')
title('y=(e^(t/10)*sin(t))/(t^2+1)') % puts title on figure

% Plotting (t,y2) as individual points and not a curve


plot(t2,y2,'o')
title('y=(e^(t/10)*sin(t))/(t^2+1)' )% puts title on figure

Patrick Hayes MWF 7:30-8:20

% Plotting (t,y2) as points with a line through them


plot(t2,y2,'o-')
title('y=(e^(t/10)*sin(t))/(t^2+1)') % puts title on figure

Patrick Hayes MWF 7:30-8:20

% Exercise 3

% Plotting a circular helix in 3 dimensions


t3= linspace(0,20,100); %t values for exercise 3 as t is greater than
and equal to 0 and less than or equal to 20
x3=sin(t3); % x as a function of t for exercise 3
y3=cos(t3); % y as a function of t for exercise 3
z3=t3; % z as a function of t for exercise 3
plot3(x3,y3,z3) % three dimensional graph of x y and z

Patrick Hayes MWF 7:30-8:20

% Exercise 4

x4= linspace(0,pi,100); % x-values for exercise 4


y4=cos(x4); % y as a function of x for exercise 4
z4= 1- (x4.^2 /2) + (x4.^4 /24); %z as a function of x for exercise 4
plot(x4,y4,'r',x4,z4,'b--') % plots two graphs for (x,y) and (x,z)
legend('y4','z4') % puts a legend on the graph
grid on % turns the grid on for the graph

Patrick Hayes MWF 7:30-8:20

% Exercise 5

x5 = linspace(0,4,100); % define the vector x in the interval [0,4]


y51 = f(x5,-1); % compute the solution with C = -1 for exercise 5
y52 = f(x5,0); % compute the solution with C = 0 for exercise 5
y53 = f(x5,1); % compute the solution with C = 1 for exercise 5
plot(x5,y51,'r-',x5,y52,'go',x5,y53,'c:') % plot the three solutions
with different line-styles
title('solutions to dy/dx=x+2') % add a title
legend('C=-1','C=0','C=1') % add a legend
function y = f(x5,C)
y = x5.^2/2 + 2*x5 + C;% fill-in with the expression for the general
solution
end

Patrick Hayes MWF 7:30-8:20

% Exercise 6

% A)
f1 = @(x,y)(x^3+(y*exp(x))/(x+1));
f1(2,-1)
clear f1
% B)
function dydx = f(x,y) % function of x and y
dydx= (x^3+(y*exp(x))/(x+1)); % defining the function
f(2,-1)
ans =
5.5370

You might also like