Plot of a function

2 次查看(过去 30 天)
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

采纳的回答

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