Calling multiple functions from inside one
Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here.Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here. Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here. functions MATLAB Answers — New Questions