How to graph a function with a parameter that changes with time.
89 views (last 30 days)
Show older comments
Abdul Qadeer Nabikhel
on 20 Sep 2020
Commented: Star Strider
on 21 Sep 2020
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.
0 Comments
Accepted Answer
Star Strider
on 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.
2 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!