フィルターのクリア

Plot of a function

2 ビュー (過去 30 日間)
Saptarshi Bhattacharjee
Saptarshi Bhattacharjee 2012 年 1 月 2 日
I have a problem where I need to plot the curve of f(x) vs x.x=[0,4]. I am having problems as to dealing with the multiple outputs of f(x). Is there a way of accessing each element of x as in arrays and then compute the value of f(x) for that x and store it in another array? Finally i can plot the curve with help of values in x and f(x) vectors
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 2 日
Please do not use my email address as a Tag.

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

採用された回答

Walter Roberson
Walter Roberson 2012 年 1 月 2 日
numx = length(x);
fx = zeros(1, numx);
for K = 1:numx
fx(K) = f(x(K));
end
plot(x, fx);
However, keep in mind that
x = [0,4];
constructs x to have exactly two values, 0 and 4. There is no MATLAB construct to express a continuous range of values. You can use the colon notation to express lists of values, such as
x = 0 : 0.1 : 4;
or you can use linspace(), such as
x = linspace(0, 4, 51);
where the 51 is the total number of points including the two endpoints.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by