Graph not lining up with the function

1 Ansicht (letzte 30 Tage)
Philosophaie
Philosophaie am 20 Okt. 2017
Bearbeitet: Himanshu am 10 Dez. 2024
Graph not automatically lining up with the function x. The t axis goes from -1 to 2 instead of -2 to 2 and the x axis goes from 1 to 3 instead of 0 to 1 like the exp. How do I override the graph axis?
for t=-2:.1:2
x=exp(-1*t);
plot(x,t,'-r');
end;

Antworten (1)

Himanshu
Himanshu am 10 Dez. 2024
Bearbeitet: Himanshu am 10 Dez. 2024
Hey,
It looks like you're trying to plot the function ( x = e^{-t} ) over the range (-2 \leq t \leq 2). However, your current approach is plotting ( x ) as the x-axis and ( t ) as the y-axis, which is the opposite of the general convention. Additionally, you're plotting each point one at a time, which results in a series of disconnected points, instead of a continuous line.
To plot the function correctly and set the axis limits as you desire, you can do the following:
% Define the range for t
t = -2:0.1:2;
% Compute x for each t
x = exp(-t);
% Plot x against t
plot(t, x, '-r');
% Set the axis limits
xlim([-2, 2]); % Set limits for the x-axis (t-axis)
ylim([0, 1]); % Set limits for the y-axis (x-axis)
% Add labels and title for clarity
xlabel('t');
ylabel('x = exp(-t)');
title('Plot of x = exp(-t)');
To learn more about the 'plot' function, please go through the following documentation page:
Hope this was helpful!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by