Matlab 2014a parachute problem

Here is the code
function dummy=parachute(c)
m=68;
g=9.81;
t=10;
v=45;
c=0.1:20:100;
dummy=-v+(g*m./c).*(1-exp(-c/m)*t);
fplot('parachut',[0,20])
grid on
xlabel('c')
ylabel('f(c)')
here is the error message I am receiving
Maximum recursion limit of 500 reached. Use
set(0,'RecursionLimit',N) to change the limit. Be
aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ismember>ismemberlegacy
I want the program to run . then I have to make a function to find "c" at 10 seconds by graphic means in the command window.
I am stuck with this error messages or another messages.

2 个评论

I fixed your formatting. Next time don't double space and just highlight your code and click the {}Code button. Please read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
By the way, your code ran fine for me.
Robert
Robert 2014-8-31
编辑:Robert 2014-8-31
Thank you for fixing it. I ran it on my desktop and it worked. But on my surface pro 2 it keeps giving my revulsion limit reached. I change the limit and it crashed. Any suggestion?

请先登录,再进行评论。

 采纳的回答

Put this command into your script:
workspace;
And then set a breakpoint near the end of your function. Make sure there are no variables that are not supposed to be there, like two variables, one of which is a misspelling of another. Try
which fplot
to make sure you don't have two functions of that name, where it might be using the one you did not expect.
When you ran it on each computer, was it the actual file, like you copied it from a flash drive or network drive? Or did you type it in on each one? Because the code looks fine, and there is no recursion that I can see and the code runs fine on at least two computers.

9 个评论

I got it to run on my surface finally. I think what happen was there was something left over in the workspace. I deleted everything and did a clear all. Then I ran it and worked like it did on my desktop.
Now how could I create a function to find a value on the graph or the command window when t=10? I tried Function c=find(t) I feel am getting close.
Thank you for your advise.
Well the function needs a lot of help before I can even answer that. For example, why are you passing in "c" and then just overwriting it with 0.1:20:100????? Was that just a debug statement you hadn't deleted yet?
And t is always 10 because you hard coded that in for t. So I don't understand your questions. So you hard code both t and c, so what is there to figure out???
And I never use fplot(). If you would consider using the regular plot(x,y) then I could help you.
I am unsure of where to hard coded c or not. I am suppose to find c using a graphic method. The hint I was given is " create a function and execute in the command window."
I think the reason I am using fplot is to plot the function. But I think I can do that using plot.
If I delete the hard coded "c", then is there some way to find "c" from the command window through a function on the graph?
Thank you for your help. I hope to get better at programming soon.
I'm really not sure how to answer. You don't find c, at least not how you've written it. You have to already know what c is and then you pass it in to the function. Maybe you want to have some code to plot a function then use ginput(1) to have the user point to a place on the graph and then find out what's the data point that is nearest to where they clicked. But I don't really have any good instructions for what is supposed to happen. Can you make a flow chart or something?
I don’t believe you need ‘c’ in the function, since fplot will evaluate ‘parachute’, substituting in ‘c’ and evaluating it to do the plot.
You were likely getting the ‘recursion limit’ error because you are calling ‘parachute’ through fplot inside your function.
I would do this:
function dummy=parachute(c)
m=68;
g=9.81;
t=10;
v=45;
dummy=-v+(g*m./c).*(1-exp(-c/m)*t);
end
then outside the function (Command Window or script m-file):
fplot('parachute',[0,20])
grid on
xlabel('c')
ylabel('f(c)')
and then use the data cursor to locate the values of the function you want.
If you’re supposed to get the ‘c’ and ‘f(c)’ values programatically, note that the documentation for fplot includes the option:
  • [X,Y] = fplot(fun,limits,...) returns the abscissas and ordinates for fun in X and Y. No plot is drawn on the screen; however, you can plot the function using plot(X,Y).
You may have to write a simple interpolation routine if the exact value isn’t returned.
I think that has been the problem since I first received this assignment. I don't think it is clear on what is wanted.
My sheet says : given the function ( which is the equation that is equal to dummy in this case) and by using the given values Find "c" using graphic method. Then my hint is create a function and execute it on the command window.
The only way I can explain this in greater detail is take the program given and run a function from the command window that will let the user find a specific point. Maybe this flow chart will help.
I think the ginput(1) might help me. If that will help me find c on the graph I am all about using it. My instruction was to create a function to do that. Maybe the instruction should have been little more clearer than they are now.
Would you hard coded c into the program ?
Thank you for all your time.
nt.
The only question I can answer with any certainty is about hardcoding ‘c’:
With fplot: No. Let fplot do it.
Without fplot: Yes, but outside of ‘parachute’.
I thought he purposely called it parachut to avoid the name conflict. that's the way his code reads. If he didn't and called it parachute in fplot, then that would cause a problem. I have no idea what that dummy stuff is, but I think the program should go like this. In file parachute.m, have both functions below:
function parachute()
fontSize = 24;
c = linspace(1, 30, 100); % $00 points between 1 and 1000
out = GetCurve(c);
fHandle = figure;
subplot(1,2,1);
plot(c, out, 'bo-', 'LineWidth', 2);
xlabel('c', 'FontSize', fontSize);
ylabel('out', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
uiwait(msgbox('Click somewhere on the curve'));
[cSelected, y] = ginput(1)
% Find distances from clicked point to every other point on the curve.
distances = sqrt((cSelected - c).^2 + (y - out).^2);
subplot(1,2,2);
plot(distances, 'bo-');
grid on;
% Find c nearest cSelected
[difference, indexOfClosest] = min(distances)
closestY = out(indexOfClosest);
xlabel('index', 'FontSize', fontSize);
ylabel('distance', 'FontSize', fontSize);
% Draw a line between them
subplot(1,2,1);
line([cSelected, c(indexOfClosest)], [y, closestY],...
'Color', 'r', 'LineWidth', 2);
message = sprintf('You clicked at (%.1f,%.1f) which is closest to (%.1f,%.3f)',...
cSelected, y, c(indexOfClosest), closestY);
uiwait(msgbox(message));
% Close down the figure window.
close(fHandle);
function out = GetCurve(c)
m=68;
g=9.81;
t=10;
v=45;
out = -v+(g*m./c).*(1-exp(-c/m)*t);
%
That is very nice. I am going to have to work on condensing your program down to a more feasible level for myself. I see how your program is more user friendly and would work more realistic. I like the message boxes. The enlarge to full screen is the most fascinating thing I have saw.

请先登录,再进行评论。

更多回答(1 个)

Robert
Robert 2014-9-1
I think I have made some strides in the last 24 hours. I ran fplot outside of parachute and also put in ginput(1) which gave me the value of "c" in the workspace.
How could I could I make some function to obtain the value of "c" to appear on the command window?

2 个评论

Thank you. I am happy with the results. I think I am going to need a lot of practice to be proficient with MATLAB.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by