Calling multiple function files to plot in one figure

2 ビュー (過去 30 日間)
Austin Leonardo
Austin Leonardo 2018 年 2 月 7 日
回答済み: Unai San Miguel 2018 年 2 月 7 日
I would like to plot multiple functions that I have created for comparison in a single figure, in this case the comparison of Eulers forward method, Eulers backwards method and trapezoid method of approximation. How I would I go about this if the headers of the files are in the format FWD_Eulers(N,f,t0,tf)?
  1 件のコメント
Stephen23
Stephen23 2018 年 2 月 7 日
Perhaps something like
FwdVals = FWD_Eulers(N,f,t0,tf)
BwdVals = BWD_Eulers(N,f,t0,tf)
TpzVals = Trapezoidal(N,f,t0,tf)
and then plot those values using your choice of plotting routine. What have you tried so far?

サインインしてコメントする。

回答 (1 件)

Unai San Miguel
Unai San Miguel 2018 年 2 月 7 日
Although I don't know exactly what kind of plots you want to do, or what are the variables involved, sometimes it helps to use the simplest plotting functions: plot, plot3 for 1 independent variable or surf, contour for 2 independent variables. Many of the more advanced plotting functions do this.
The procedure is as follows:
  1. Decide what kind of plot you want to do
  2. Evaluate your functions over a grid of values for the independent variables
  3. plot the points, or surf or contour them.
For instance, the fplot function allows you to plot a function (of 1 independent variable) from the equation of that function. But you can just calculate a number of points and use the simpler plot
Example in the documentation:
xt = @(t) cos(3*t);
yt = @(t) sin(2*t);
fplot(xt,yt)
Example with plot:
tp = linspace(-5, 5, 101);
xtp = cos(3 * tp);
ytp = sin(3 * tp);
plot(xtp, ytp, '-')

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by