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

14 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 20 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by