0% found this document useful (0 votes)
10 views2 pages

Line Plot and 2 D

The document provides MATLAB code for generating a 3D parametric plot and a 2D contour plot based on user-defined functions and ranges. Users are prompted to input function handles for x(t), y(t), and z(t) for the 3D plot, and a function handle for f(x,y) for the contour plot, along with their respective ranges and number of points. Example functions and ranges are provided for both types of plots.

Uploaded by

mranonymous11211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Line Plot and 2 D

The document provides MATLAB code for generating a 3D parametric plot and a 2D contour plot based on user-defined functions and ranges. Users are prompted to input function handles for x(t), y(t), and z(t) for the 3D plot, and a function handle for f(x,y) for the contour plot, along with their respective ranges and number of points. Example functions and ranges are provided for both types of plots.

Uploaded by

mranonymous11211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LINE PLOT

%Prompt user for parametric equations as function handles


fx = input('Enter the function for x(t) as a function handle :');
fy = input('Enter the function for y(t) as a function handle :');
fz = input('Enter the function for z(t) as a function handle :');
%Ask user for the parametric range [t_start, t_end]
t_start = input('Enter the start value of t :');
t_end = input('Enter the end value of t :');
num_points = input ('Enter the number of points to plot:');
%Generate the parametric range dynamically
t = linspace(t_start, t_end, num_points);
%Evaluate the parametric functions
x=fx(t);
y=fy(t);
z=fz(t);
%Plot the parametric curve using plot3
figure;
plot3(x,y,z,'r','LineWidth',2);
grid on;
%Labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Parametric Plot using plot3');

Example :
Consider the coordinates x,y and z given as a function of the parameter t by
x = √t sin(2t)
y = √t cos(2t)
z = 0.5t
for 0 ≤ t ≤ 6π
2-D CONTOUR

%User input for the function of x and y


fxy=input('Enter the function f(x,y) as a function handle:');
%User input for x and y range
x_start=input('Enter the start value for x:');
x_end=input('Enter the end value for x:');
y_start=input('Enter the start value for y:');
y_end=input('Enter the end value for y:');
num_points=input('Enter the number of points in each direction');
%Generate grid for x and y
x = linspace(x_start, x_end, num_points);
y = linspace(y_start, y_end, num_points);
[X,Y] = meshgrid(x,y); %Create 2D grid
%Compute function values
Z=fxy(X,Y);
%Plot 2D Contour
figure;
contour(X,Y,Z,20,'LineWidth',1.5);%20 contour levels
grid on;
%Labels and Title
xlabel('X-axis');
ylabel('Y-axis');
title('2D Contour Plot');

Example :
2 2
The function z = 1.8-1.5√(x + y )sin(x)cos(0.5y)
over the domain -3 ≤ x ≤ 3 and -3 ≤ y ≤ 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy