How to graph a function with a parameter that changes with time.

14 Ansichten (letzte 30 Tage)
I'm using Matlab to plot a function that varies with time. So for example I want to plot a function y = (1/(t+1))*exp(-t*x^2) where t changes values with time. So for example at start it takes t=0 value and as time passes the value of t increases little by little. I can graph a simple y=exp(-x^2) using linspace () and plot() but idk how to plot with time as a variable. Please help.

Akzeptierte Antwort

Star Strider
Star Strider am 20 Sep. 2020
It is straightforward to define and calculate the result of ‘y’ while varying both ‘t’ and ‘x’ at the same time, using matrix arguments to ‘y’.
Example —
y = @(t,x) (1./(t+1)).*exp(-t.*x.^2); % Create As Anonymous Function
t = linspace(0, 10, 25); % Define ‘Time’ Vector
x = linspace(-2, 2, 15); % Deffine ‘Position’ Vector
[T,X] = ndgrid(t,x); % Create Matrices For Both (Can Also Use ‘meshgrid’)
figure
surfc(T,X,y(T,X))
grid on
xlabel('t')
ylabel('x')
zlabel('y')
Experiment to get different results.

Weitere Antworten (0)

Kategorien

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

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by