I need help with using the input function
1 view (last 30 days)
Show older comments
Here is my assignment: Repeat the Fence problem from three assignments ago, this time saving it as a script and using the input() function rather than having constants for area, straight cost, and curved cost values. The upper limit for the radius independent variable should be computed (assume length of zero). Use disp() and [ ] to construct sentences to deliver the answers. The format string within num2str should be used to limit the numbers to two decimal places. Here is my code from my last assignment:
>> Area = 1600;
>> StrCo = 30;
>> CurCo = 40;
>> R = [.01:.01:sqrt(2*Area/pi)];
>> L = (Area-.5*pi*R.^2)./(2*R);
>> Cost = (2*L+ 2*R)*StrCo +pi*R*CurCo;
>> [BestCost, Index] = min(Cost)
BestCost =
5.1575e+03
Index =
1861
>> BestR = R(Index)
BestR =
18.6100
>> BestL = L(Index)
BestL =
28.3714
I'm just having a lot of trouble saving this as a script and I have no clue how to use the input() function in this case! Just to clarify, R=Radius, StrCo = Straight Cost, CurCo = Curved Cost, and L=Length
0 Comments
Answers (1)
Stephen23
on 28 Feb 2018
Edited: Stephen23
on 28 Feb 2018
"I'm just having a lot of trouble saving this as a script and I have no clue how to use the input() function in this case!"
It is not required that you (or I, or anybody) knows how to do everything in advance, before they start to do some task. Because when they take the time to read the documentation and do some very simple investigation then they will learn what tools and method they have available to them, and how to use any functions that they need to use.
Instead of feeling lost and helpless, the best start is always to start reading. For example, you can use the internet: when I search for "MATLAB script" these are the first two pages the come up using my favorite internet search engine:
and for "MATLAB input" I get this:
Those pages contain explanations and examples, and they are available for everyone to read. And the more your read them, the more you will learn, and the easier it will be for you to find information in future:
I highly recommend that do the introductory tutorials, which teach many basic concepts that you will find indispensable when using MATLAB:
PS: to get you started:
R = str2double(input('Input the radius value: ','s'));
L = str2double(input('Input the length value: ','s'));
...
If you don't know what those functions are doing, then read their help pages, and try the examples. Your computer will not explode if you make a mistake, so start experimenting!
2 Comments
Stephen23
on 28 Feb 2018
@Travis Ward: I hope that it helps. You should also accept the answer that helped you most.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!