How can I plot my function?
古いコメントを表示
My program is supposed to plot a function, but every time I try this I either end up with an empty plot or with an error. The code is this:
function Q = hydrogenusage(P)
Q = (120*P)-(P^2);
plot(P,Q)
xlabel('Power')
ylabel('Usage')
title('Hydrogen usage')
grid on
end
The error I get is 'Not enough input arguments'. Okay, I thought, it needs some kind of input. So I entered:
hydrogenusage(0)
But if I try that it gives me an empty plot. I tried varying the 0 value I added as input, but it didn't work. How can I make this work?
採用された回答
その他の回答 (1 件)
Walter Roberson
2014 年 1 月 14 日
It is plotting, but it is only plotting a single point because you only asked it to plot a single point. You need to pass in a vector of points such as
hydrogenusage(0:10)
You will find you also need to change P^2 to P.^2
カテゴリ
ヘルプ センター および File Exchange で Surfaces, Volumes, and Polygons についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!