Not sure what to do on this question.

4 ビュー (過去 30 日間)
Brian
Brian 2013 年 3 月 26 日
write a matlab script that allowss the user to plot one to plot one of the following functions over the range 0 less than or equal to x equal to or less than 10. x<=x<=10
f1(x)=cos(x)
f2(x)=sin(x)
f3(x)=(-x^2)+10x
Using the input command, your script should ask the user to select which function to plot. Then , the script should generate the desired plot.
I'm not really sure what i'm supposed to do for this problem, the things covered in the book seem a bit vague to me.

回答 (3 件)

Walter Roberson
Walter Roberson 2013 年 3 月 26 日
was the input 1? If so then plot cos(x). Wss the input 2? If so then plot sin(x). And so on.
  2 件のコメント
Brian
Brian 2013 年 3 月 26 日
no its function 1, function 2, function 3. The numbers aren't inputs.
Walter Roberson
Walter Roberson 2013 年 3 月 26 日
"your script shuld ask the user to select which function to plot". That does not say that you must allow the user to use a string answer to make the selection.

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


Image Analyst
Image Analyst 2013 年 3 月 26 日
編集済み: Image Analyst 2013 年 3 月 26 日
I would use the menu function:
button = menu('Select one',...
'f1(x)=cos(x)',...
'f2(x)=sin(x)',...
'f3(x)=(-x^2)+10x')
if button == 1
% Plot function 1
elseif button == 2
% Plot function 2
else
% Plot function 3
end
But if it requires the input() function, there are examples in the help for that, which you should easily be able to adapt.

Youssef  Khmou
Youssef Khmou 2013 年 3 月 26 日
hi, try his basic sol :
% SCRIPT
x=0:0.1:10;
fprintf(' SELECT A FUNCTION TO PLOT :\n case1 : cos(x) \n case(2) sin(x) .\n case (3) : -x^2+10x :\n');
a=input('');
if a==1
figure, plot(x,cos(x));
elseif a==2
figure, plot(x,sin(x));
elseif a==3
figure, plot(x,-x.^2+10*x);
end
  2 件のコメント
Youssef  Khmou
Youssef Khmou 2013 年 3 月 26 日
編集済み: Youssef Khmou 2013 年 3 月 26 日
you should add another input for resolution or step dx , and also the lower and upper limits , its easy i think .
fprintf(' enter step dx \n');
.....
dx=input('');
.............
Image Analyst
Image Analyst 2013 年 3 月 26 日
You don't need the figure command - plot will automatically create a figure. And usually we don't do the entire homework for them - we leave at least something for them to do.

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

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by