Rescursion Limit Reach?

When I try to run so I call values spring(200,10000,15000,0.1) I keep getting a Rescursion Error message. When I set the recursion level higher MatLab crashes. Any ideas how I can fix this. Code below: function x=spring(W,k1,k2,d) if ((W/k1)<d) x= W/k1; else x=(W + 2*d*k2)/(k1 + 2*k2); end
clf %clears the current figure window
hold on %creates new axes
st=5; %step by 5
for W=0+st:st:3000-st;% W is between 0 and 3000 and creates a loop
x= spring(W,k1,k2,d);
plot(W,x)
end

回答(1 个)

Paulo Silva
Paulo Silva 2011-4-26

0 个投票

You have the spring function inside one m file called spring.m and the script that calls the spring function inside another file called something else? you run the script and you get the error about the recursion?! you are calling the spring function inside itself for sure, don't do that.

2 个评论

I was suppose to write another function (to graph) that uses the function I already have above in the same .m file.
That won't work, the function you made is called from the outside so you must have another script or function that calls the spring function.
I'm going to post a better code in your other Question, that code you are using was just to show a simple way to do it, it's very inefficient.

请先登录,再进行评论。

类别

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

提问:

2011-4-26

Community Treasure Hunt

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

Start Hunting!

Translated by