Multiple formulas in one function?

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!

 Respuesta aceptada

Image Analyst
Image Analyst el 31 de Mzo. de 2018
Sure, just compute and return the numerical results
function [n,mu,M,lambda, etc] = Compute7Formulas(inputs)
n = ......whatever
M = ...... whatever....
lambda = whatever
% etc.

7 comentarios

gblmtc
gblmtc el 31 de Mzo. de 2018
Thank you!
I’ll give it a try! ;)
gblmtc
gblmtc el 31 de Mzo. de 2018
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 el 31 de Mzo. de 2018
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 el 31 de Mzo. de 2018
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 el 1 de Abr. de 2018
"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 el 1 de Abr. de 2018
Thank you!
I will try that!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 31 de Mzo. de 2018

Comentada:

el 1 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by