Matlab 2014a parachute problem

7 vues (au cours des 30 derniers jours)
Robert
Robert le 31 Août 2014
Commenté : Robert le 2 Sep 2014
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 commentaires
Image Analyst
Image Analyst le 31 Août 2014
Modifié(e) : Image Analyst le 31 Août 2014
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 le 31 Août 2014
Modifié(e) : Robert le 31 Août 2014
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?

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 31 Août 2014
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 commentaires
Image Analyst
Image Analyst le 1 Sep 2014
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);
%
Robert
Robert le 2 Sep 2014
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Robert
Robert le 1 Sep 2014
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 commentaires
Image Analyst
Image Analyst le 1 Sep 2014
fprintf('The value of c = %f', c);
Robert
Robert le 1 Sep 2014
Thank you. I am happy with the results. I think I am going to need a lot of practice to be proficient with MATLAB.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by