How to graph a function with a parameter that changes with time.
95 ビュー (過去 30 日間)
古いコメントを表示
Abdul Qadeer Nabikhel
2020 年 9 月 20 日
コメント済み: Star Strider
2020 年 9 月 21 日
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 件のコメント
採用された回答
Star Strider
2020 年 9 月 20 日
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!