How to graph an equation with one independent variable?

10 ビュー (過去 30 日間)
Nathan Clark
Nathan Clark 2015 年 3 月 1 日
回答済み: John D'Errico 2015 年 3 月 1 日
I have the equation:
c=(M/(pi*4*D*t))*exp((-r^2)/(4*D*t));
All of the variables,(M,D and t) are defined above the equation and i want to graph this equation where C is the dependent variable and r is the independent variable. How do I go about doing this? Thanks

採用された回答

John D'Errico
John D'Errico 2015 年 3 月 1 日
Just use ezplot. Assume the other variables are defined in advance. Else how could you plot it if they are not?
M = ???
D = ???
t = ???
Cfun = @( r) (M/(pi*4*D*t))*exp((-r.^2)/(4*D*t));
ezplot(Cfun)
Note the use of r.^2, to allow ezplot to use vectorized calls to this function handle.
If you wish to specify the axis limits, ezplot allows you to do so in the second argument.

その他の回答 (1 件)

dpb
dpb 2015 年 3 月 1 日
First rewrite the equation to be able to use vector inputs using the "dot operatiors"
c=(M/(pi*4*D*t))*exp((-r.^2)/(4*D*t));
then set a range of r and evaluate
r=linspace(rStart,rEnd);
c=(M/(pi*4*D*t))*exp((-r.^2)/(4*D*t));
plot(r,c)
Done.

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by