Defining variables inside functions
이전 댓글 표시
Hi guys,
I'm having a lot of trouble getting my MATLAB script to work. It's a function which uses the bisection method to find the solution to an equation. The programme looks like this:
eps_abs=1E-4;
eps_step=2.9E6;
a=550E6;
b=650E6;
while ((b-a)>=eps_step || (abs(neuber2(a))>=eps_abs && abs(neuber2(b))>=eps_abs))
c=(a+b)/2;
if(neuber2(c)==0)
break;
elseif(neuber2(a)*neuber2(c)<0)
b=c
else
a=c
end
end
The function neuber2 is defined in the following MATLAB .m file:
function y = neuber2(DS)
y=(DS/E)+2*(DS/2*k)^(1/n)-(DSe*DEe/DS);
The values E, k, n, DSe and DEe have all been previously calculated in a third .m file and made global. After running this file and calculating the values of E, k, n, DSe and DEe, I then run the programme which performs the bisection method. I instantly get a warning saying that the variables in the function neuber2 are undefined.
Inserting the numerical values of the variables directly into the function makes the bisection mathod script run properly, but that's not how I want it to work, because E, k, n etc. can be different depending on how they're calculated beforehand. So, I want the function neuber2 to have these variables declared symbolically (as shown in the code) and call their current value from the original script that calculated them.
I hope you can help :)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!