Hi there!
I have attached 2 pics. There are 7 formulas, the second formula uses the output from the first formula, the third formula uses the output from the second one and so on.
My question is: could I put all these formula in just one function?
I’ve tried creating a function for each formula and after that to include all of them in one big function but it’s not working :(. I don’t know how to call the big function.
Maybe is there somebody and could give me hint for this.
Thank you!

 채택된 답변

Image Analyst
Image Analyst 2018년 3월 31일

0 개 추천

Sure, just compute and return the numerical results
function [n,mu,M,lambda, etc] = Compute7Formulas(inputs)
n = ......whatever
M = ...... whatever....
lambda = whatever
% etc.

댓글 수: 7

gblmtc
gblmtc 2018년 3월 31일
Thank you!
I’ll give it a try! ;)
I did the function as you said and I get this error.
Do you have any idea why?
Thank you!
function [tk,mk,ek,vk,uk,rk,ik,lamdak]= computeformulas(t,toe,mo,u,a,n,e,o,cuc,cus,crc,crs,io,i,cic,cis,oe,om,omo)
function [tk]= time(t,toe)
ti=t-toe;
if ti>302400
tk= ti-604800;
elseif tk<-302400
tk = ti+604800;
end
end
mk = mo +(sqrt(u)/sqrt(a^3)+n)*tk;
ek= mk/(1-e);
vk = atan(sqrt(1-e^2)*sin(ek))/cos(ek)-e;
uk = o + vk + cuc*cos(o+vk) + cus*sin(o+vk);
rk= a(1-e*cos(ek))+crc*cos(2)*(o+vk)+crs*sin(2)*(o+vk);
ik = io+i*tk+cic*cos(2)*(o+vk)+cis*sin(2)*(o+vk);
lamdak= omo + (om - oe)*tk - oe*toe;
end
This is the function I did! Is it ok that I put function in function?
Image Analyst
Image Analyst 2018년 3월 31일
Nested functions are okay, but you should not name your function time since that is a built-in function. Also, you never seem to call the badly-named time inside computeformulas, and so the tk value will never be computed.
Next, what values did you pass in to computeformulas() for t, toe, mo, etc.? It doesn't look like you passed in anything.
gblmtc
gblmtc 2018년 3월 31일
Again thanks for your help!
I’m pretty new working with the MATLAB and I’m all learning from the internet.
#1 I don’t understand what should I do with the function time ( as long as it’s a built-in one). Should I create it out and call it in the computeformulas function?
#2 regarding the values, what I did is the following: I first did the function and after that I manually introduced all the values ( t=3; toe=5;..) and after that , in editor I just pressed “ run” function. That’s not good, right?
Stephen23
Stephen23 2018년 4월 1일
"I’m pretty new working with the MATLAB and I’m all learning from the internet."
There is a lot of outdated and really bad MATLAB advice on the internet. The best source for learning MATLAB is the MATLAB documentation:
Make a separate m-file called test.m. In it, have these lines of code
t=3; % Define an input.
toe=5; % Define another input.
%etc. % Define even more inputs.
[n, mu, M, lambda, etc] = Compute7Formulas(t, toe, etc)
where you replace etc with all the other various variables you need. Then you can have the cursor in test.m (NOT in Compute7Formulas.m) and click the green run arrow or type F5.
gblmtc
gblmtc 2018년 4월 1일
Thank you!
I will try that!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2018년 3월 31일

댓글:

2018년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by