Professional Documents
Culture Documents
MATLAB ASSIGNMENT 1
Purpose: Using Matlab to create plots of single variable functions in the xy-plane
Commands Used:
linspace (a, b, n)
diff(f(x),k,x)
f = @(x,y,z,t,)vectorized expression
subs(expression)
plot (x,y,)
clear all
[a:b:c]
clc
clf reset
figure(k)
hold on/off
title('Your title','color','your color', 'FontName','Your
Font','FontWeight','bold','FontSize',12)
legend('String1','String2',,'Location', 'the location')
set(handle, other options)
set(gca, other options)
xlabel ('String', other options)
ylabel ('String', other options)
axis square/equal
axis([a, b, c, d])
grid on/off
and its
. The x-axis tick
.
MATLAB CODE
clear all
clc
dfx = diff(f(x),x);
g = @(x)subs(dfx);
%function g(x).
% clear the current figure window and reset it to its default values.
figure(1)
hold on
PLOT2 = plot (domg, g(x));
title
sin(x)sin(x^2)','by','Foster,Antony'},'color','red','FontName','mathematica','FontWeight','bold','FontSize', 12)
legend ('f(x)','f'(x)','Location','NorthWest')
set (PLOT1,'Color','black','LineWidth','3','LineStyle','-')
set (PLOT2,'Color','red','LineWidth','3','LineStyle','-')
set (gca,'XTick', [-pi:pi/2:pi],'XMinorTick','on','XTickLabel', {'-pi','pi/2','0','pi/2','pi'},'FontName','mathematica','FontWeight','bold')
set(gca,'YTick',[-7:7],'YMinorTick','on','FontName','mathematica','FontWeight','bold')
xlabel ('X-Axis','Color','red','FontName','mathematica','FontWeight','bold','FontSize',12)
ylabel ('Y-Axis','Color','red','FontName','mathematica','FontWeight','bold','FontSize',12)
axis ( [-pi pi -7 7])
grid on
END OF CODE
F(x)
F`(x)
4
3
Y-Axis
2
1
0
-1
-2
-3
-4
-5
-6
-7
-pi
-pi/2
X-Axis
pi/2
pi
and
on the interval
PLOT1 = plot(domf,f(x));
hold on
PLOT2 = plot(domg,g(x) );
hold off
title({'Graph
1','by','Foster,Antony'},'Color','red','FontName','mathematica','FontWeight','bold','FontSize',12)
legend('sqrt(1-x^2)','-sqrt(1-x^2)','Location','NorthEastOutside')
set(PLOT1,'Color','black','LineWidth',3,'LineStyle',':')
set(PLOT2,'Color','black','LineWidth',3,'LineStyle','-')
set(gca,'XTick',[-1:1/2:1],'XMinorTick','on','XTickLabel',
{'-1','-1/2','0','1/2','1'},'FontName','mathematica','FontWeight','bold')
set(gca,'YTick',[-1:1/2:1],'YTickLabel',{'-1','-1/2','0','1/2','1'},
'YMinorTick','on','FontName','mathematica','FontWeight','bold')
xlabel('X-Axis','Color','red','FontName','mathematica','FontWeight',
'bold','FontSize',12)
ylabel('Y-Axis','Color','red','FontName','mathematica','FontWeight',
'bold','FontSize',12)
axis square equal
axis([-1
grid on
1 -1
1])
END OF CODE
Y-Axis
1/2
-1/2
-1
-1
-1/2
1/2
X-Axis