Assignment help for MATLAB? Overall confusion and unable to interpret instructions fully, as well as code problems.

2 views (last 30 days)
So I have this assignment:
When using the values 5, 3, 1.6, 2.6, and 400 as inputs for the function, I should get the graph above.
However, with my code, I get this instead:
This is my code (I know it is incomplete and missing stuff, but I'm trying to take this one step at a time and I can't move on until I get the first part working):
function [Tmin,D_Tmin]=Tension(Lb,Lc,Dmin,Dmax,W)
D=(Dmin:Dmax:50);
T=(Lb*Lc*W)./(D.*sqrt((Lc^2)-(D.^2)));
plot(D,T,'bd')
axis([1.6 2.6 1300 1550]);
end
I also don't understand how their graph has two lines; where does the second, green line come from? How does the fact that the function has two outputs play into this? How do I establish the difference for the functions for Tmin and Tmax? What about my D values? Am I supposed to be checking for imaginary numbers and/or excluding them? How do I do that? Am I supposed to be checking them for min and max? If so, how do I do that? I'm just overall very confused about the assignment instructions in general and how to inc operate them into code, and why my code doesn't really produce anything at all. Note that things like graph labels and such are things I don't need help with; I just do those last.
IMPORTANT:
I AM NOT looking for someone to just do the whole thing for me; that would be cheating and I wouldn't learn anything. I'm looking for help that points me in the right direction, gives example code, etc. I don't know what's wrong and even I did, I doubt I'd know how to fix it.

Accepted Answer

Stephen23
Stephen23 on 28 Sep 2017
Edited: Stephen23 on 28 Sep 2017
Take a deep breath, you are doing just fine!
"I don't know what's wrong and even I did, I doubt I'd know how to fix it."
Here are two really important skills that you should start practicing:
  1. read the documentation for every function and command that you are using.
  2. check and test that every line does exactly what you need it to, before moving on to the next line. This means run it and check its output using different test cases.
If you had done these two steps then you would have learned that your very first line of code
D=(Dmin:Dmax:50);
does not help you to solve your task, and does not do what you think it does. Lets have a look:
>> D = 1.6:2.6:50;
>> numel(D)
ans = 19
When you read the colon documentation you will find out why this does not produce fifty values. You can also experiment in the command line, just like I did. You would also learn why this command is not suitable for this task, and when you would scroll to the bottom of that help page you would find some links to other functions... taking a few minutes to read each of their descriptions, you would find that linspace does exactly what you need:
D = linspace(...);
"where does the second, green line come from?"
Once again, if you had read the plot documentation then you would know the answer to this: there is no second green line. That plot contains just one line, which is green and has blue diamond markers. The plot documentation gives plenty of examples of how lines have colors, thicknesses, markers, and other options to pick from: there is only one line.
"How does the fact that the function has two outputs play into this?"
It plays absolutely no part in the plotting, but presumably (you do not say) you have to submit your work to get assessed or marked, in which case the outputs will likely be used to check that your function implements the formula correctly.
"How do I establish the difference for the functions for Tmin and Tmax?"
It is not clear why you want to get Tmax, because the assignment only asks you for Tmin. And once again, a little internet search for "MATLAB minimum" finds you the correct function (hint: min). And when you read its help you will find that it also returns an index as its second output, which you can use to get the D value corresponding to the Tmin value.
"Am I supposed to be checking for imaginary numbers and/or excluding them? How do I do that? Am I supposed to be checking them for min and max? If so, how do I do that?"
The assignment does not ask for any of this. Do not invent unnecessary complicating obstacles. Focus on the given task. If there was a need to deal with imaginary numbers then the assignment would mention it to be sure, or you could deal with it when it occurs.
Summary
Always read the documentation for all commands, no matter how trivial. Always check your code by hand: experimenting and trying things out is easy to do, and it does not cause your computer to explode if you make a mistake.
Do not just write code and hope that it is correct: code does not care what you think/wish/imagine/believe/want it to be doing. Code does not read your mind. You have to check what the code is actually doing.
For more tips and useful suggestions on how to learn how to use MATLAB efficiently:
  1 Comment
Sarah Pierson
Sarah Pierson on 28 Sep 2017
Thank you! I got it working now! I don't have time to go into the specifics though as I'm writing this right before one of my classes. But again, thank you. :)

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 28 Sep 2017
D=(Dmin:Dmax:50); is almost certainly wrong. The increment goes in the middle;
D = Dmin:50:Dmax;
  1 Comment
Steven Lord
Steven Lord on 28 Sep 2017
And that's only if you want to increase in steps of 50. If you don't know how large the steps should be, but know how many steps you want, look at the linspace function.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!