Plotting XY Data
Syntax
plot(X,Y, 'options')
creates a 2-D line plot of the data in Y versus the
corresponding values in X, where X and Y are vectors of the same
length.
Plotting function
fplot(f,xinterval)
plots expression or function f over the specified
interval. Specify the interval as a two-element vector of the form [xmin xmax].
If we did not mention xinterval,
fplot plots the function f over the default interval
[-5 5] for x
Example
Plot the functions $$y1=50cos(x)sin(x),\\y2=4x^3-4x+14,\\y3=10x$$ in the range [-2,2].
Using plot
clc
clear
close
x = [-2:0.01:2];
%Define the functions to
plot
y1 = 50*cos(x).*sin(x);
y2 = 4*x.^3-4*x+14;
y3 = 10*x;
plot(x,y1,'b','linewidth',1)
hold on
plot(x,y2,'--r','linewidth',1)
plot(x,y3,'-.m','linewidth',1.5)
hold off
%Customization (Optional)
xlabel('\bf x-Axis');
ylabel('\bf y-Axis')
title('\fontname{Arial}
Cartesian Plot','fontsize',14)
legend('y1','y2','y3')
Output
Using plot
clc
clear
close
syms x
y1 = 50*cos(x)*sin(x);
y2 = 4*x^3-4*x+14;
y3 = 10*x
fplot([y1,y2,y3],[-2,2])
%Customization
(Optional)
xlabel('\bf x-Axis'); ylabel('\bf
y-Axis')
title('Cartesian Plot','fontsize',14)
legend('y1','y2','y3')
Output
Plotting Polar plot
Syntax
polarplot(theta,rho)
plots a line in polar coordinates, with theta indicating
the angle in radians and rho indicating the radius value for each point. The
inputs must be vectors of equal length or matrices of equal size.
Example
Plot the graph of the polar curves $$r=cos(2\theta); r=sin(3\theta)$$
clc
clear
close all
t=linspace(0,2*pi);
r1=input("Enter the first polar curve r1=f(t): r1=");
r2=input("Enter the second polar curve r2=f(t): r2=");
polarplot(t,r1,'m',t,r2,'b','linewidth',2);
Output
No comments:
Post a Comment