Plot of a function

조회 수: 1 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by