1 / 7100%
LAB 1 - Your Name - MAT 275
Exercise 1
NOTE: Please suppress output - i.e., use a semicolon ';' at the end of any commands for which the output is not
necessary to answer the question. Delete these notes before turning in.
Define input variable theta as discretized row vector (i.e. array)
theta =[0, pi/9 , pi/7, pi/6, (7*pi)/6, (8*pi)/7,(9*pi)/8 ];
Define radius
r=9;
Define x and y in terms of theta and r
x= r*cos(theta);
y= r*sin(theta);
Check that x and y satisfy the equation of a circle
r=((x.^2)+(y.^2)).^0.5
r = 1×7
9 9 9 9 9 9 9
Explain results here. Do x and y satisfy the equation of a circle? Why or why not?
"no, bcz circle equation is Y^2+X^2=r^2 "
ans =
"no, bcz circle equation is Y^2+X^2=r^2 "
How does the vector output at the end confirm your answer?
"the plot is not shown as acircle "
ans =
"the plot is not shown as acircle "
Exercise 2
Define t-vector
%%
t= 1:0.05:5;
Define y-vector
y = (exp(t./15) .* cos(2* t)) ./ ( (0.2* t).^3 + 5);
Part (a)
Plot results (should have 3 plots total)
figure;
plot(t,y,'k-','LineWidth',2);
title('y')
Part (b)
Plot results as data points only and as data points with line.
figure %creates another figure window
plot(t,y,'ko-','LineWidth',2);
title('y')
Exercise 3
Create t-vector (choose enough elements so that plot is smooth!)
t = 0:0.01:10;
%a smuch number as possibable to make it smoother
Define x, y, x components in terms of t
x = 7*cos(4*t);
y = 7*sin(4*t) ;
z = 6*t;
Plot results
figure;
plot3(x,y,z)
grid on
NOTE: if graph does not look smooth use more elements in your t-vector -- i.e. use smaller stepsize between
elements. Delete these notes before submission.
Exercise 4
Define input variable as vector
x= linspace((-pi/5),(pi/5),100);
Define y and z
y = sin(5*x);
z =(5*x)-((125/6)*x.^3);
Plot results
figure;
plot(x,y,'r',x,z,'--');
axis tight;
grid on
Exercise 5
NOTE: you must create the M-file ex5.m separately and invoke it here in your livescript file. Delete these notes
before submission.
type ex5.m
type ex5.m
x=0:0.01:4;
%[0,4]
%indintphai the y1,y2,y3
y1= f(x,60);
y2= f(x,100);
y3= f(x,160);
%polt them
plot(x,y1,'-r',x,y2,'--b',x,y3,'-k');
%the title
title("Solutions to dy/dx = −7x + 17x2 − 6 cos(x)");
legend('C=y1','C=y2','C=y3');
grid on
% fill-in
% the function
function y=f(x,c)
y = (-7/2)*x.^2 + (17/3)*x.^3-6*sin(x)+ c;
end
Run your M-file--i.e. execute the M-file
run 'ex5.m'
type ex5.m
x=0:0.01:4;
%[0,4]
%indintphai the y1,y2,y3
y1= f(x,60);
y2= f(x,100);
y3= f(x,160);
%polt them
plot(x,y1,'-r',x,y2,'--b',x,y3,'-k');
%the title
title("Solutions to dy/dx = −7x + 17x2 − 6 cos(x)");
legend('C=y1','C=y2','C=y3');
grid on
% fill-in
% the function
function y=f(x,c)
y = (-7/2)*x.^2 + (17/3)*x.^3-6*sin(x)+ c;
end
Exercise 6
Part (a)
Define g as anonymous function
g = @(x,y)((x.^7/y^2)+ (cos(5*x.*exp(6*y))/(x.^3+7)));
Evaluate g at the given values of x and y
g(3,-1);
Part (b)
NOTE: You need to create a separate M-file (g.m) and invoke it in the main file, here. Erase these notes upon
submission.
Clear the function g out of the workspace
clear g
Print out g.m contents
type 'g.m'
type 'g.m'
function g =f(x,y)
g = ((x.^7/y^2)+ (cos(5*x.*exp(6*y))/(x.^3+7)));
end
Evaluate g at the given values of x and y
g(3,-1);
Attempt to execute SCRIPT g as a function:
/Users/mhmdalzhymy/Desktop/g.m
The End!!!
Powered by TCPDF (www.tcpdf.org)
Students also viewed