Issue with calling variables through multiple functions, not enough input arguments

5 次查看(过去 30 天)
Hi all, I'm still farily inexperienced with matlab. I am trying to break up an equation into smaller parts (the 4 functions) to make it easier to check/modify when I integrate the Gammasigma function but I keep getting 'not enough input arguments,' and the error lists every function as part of the error. I know that I am doing something wrong with the variable calls but I am not sure what specifically my issue is or how to fix it.
syms Egam
ECrit = 5;sigmaT = 1; me = 510;
compton1 = vpaintegral(Gammasigma,Egam,15,30);
compton2 = vpaintegral(Gammasigma,Egam,11,30);
compton = compton1/compton2;
function Gs = Gammasigma(Egam,ECrit,sigmaT,me)
Gs = (exp(-exp(-((log(Egam)+1.2)./(.8)))-((log(Egam)+1.2)./(.8))+1)).*s3;
end
function sigma3 = s3(Egam,ECrit,sigmaT,me)
sigma3 = s2+(3.*sigmaT)./(8).*(1)./(((Egam)./(me)).^3).*(1-((Egam)./(me))-(1+2.*((Egam)./(me)))./(1+((Egam)./(me)) ...
.*(1-(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam)))))-((Egam)./(me)).*(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam))));
end
function sigma2 = s2(Egam,ECrit,sigmaT,me)
sigma2 = s1+(3.*sigmaT)./(8).*(1)./(2.*((Egam)./(me))).*((1)./(1+((Egam)./(me)).*(1-(1-(me)./(Egam).*((ECrit)./(Egam)) ...
./(1-(ECrit)./(Egam))))).^2-(1)./(1+2.*((Egam)./(me))).^2);
end
function sigma1 = s1(Egam,ECrit,sigmaT,me)
sigma1 = (3.*sigmaT)./(8).*((((Egam)./(me)).^2-2.*((Egam)./(me))-2)./(((Egam)./(me)).^3).*log((1+2.*((Egam)./(me))) ...
./(1+((Egam)./(me)).*(1-(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam)))))));
end
Any help would be greatly appreciated!

采纳的回答

Walter Roberson
Walter Roberson 2021-1-29
function Gs = Gammasigma(Egam,ECrit,sigmaT,me)
Gs = (exp(-exp(-((log(Egam)+1.2)./(.8)))-((log(Egam)+1.2)./(.8))+1)).*s3;
That invokes the function s3 without passing any input arguments.
Remember that s3 might have been written
function sigma3 = s3(me_,sigmaT_,Egam_,ECrit_)
sigma3 = s2+(3.*sigmaT_)./(8).*(1)./(((Egam_)./(me_)).^3).*(1-((Egam_)./(me_))-(1+2.*((Egam_)./(me_)))./(1+((Egam_)./(me_)) ...
.*(1-(1-(me_)./(Egam_).*((ECrit_)./(Egam_))./(1-(ECrit_)./(Egam_)))))-((Egam_)./(me_)).*(1-(me_)./(Egam_).*((ECrit_)./(Egam_))./(1-(ECrit_)./(Egam_))));
end
MATLAB absolutely will not look at the calling sequence of the function to be called and match up the formal parameter names to find the closest name in the workspace and use that as the parameter. You must explicitly pass all parameters to a function being called.
  2 个评论
James Kennedy
James Kennedy 2021-1-29
Thank you so much for your help. I fixed the function calls to have all the variables in the equations
syms Egam
ECrit = 5;sigmaT = 1;me = 510;
compton1 = vpaintegral(Gammasigma,Egam,15,30);
compton2 = vpaintegral(Gammasigma,Egam,11,30);
compton = compton1/compton2;
function Gs = Gammasigma(Egam,ECrit,sigmaT,me)
Gs = (exp(-exp(-((log(Egam)+1.2)./(.8)))-((log(Egam)+1.2)./(.8))+1)).*s3(Egam,ECrit,sigmaT,me);
end
function sigma3 = s3(Egam,ECrit,sigmaT,me)
sigma3 = s2(Egam,ECrit,sigmaT,me)+(3.*sigmaT)./(8).*(1)./(((Egam)./(me)).^3).*(1-((Egam)./(me))-(1+2.*((Egam)./(me)))./(1+((Egam)./(me)) ...
.*(1-(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam)))))-((Egam)./(me)).*(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam))));
end
function sigma2 = s2(Egam,ECrit,sigmaT,me)
sigma2 = s1(Egam,ECrit,sigmaT,me)+(3.*sigmaT)./(8).*(1)./(2.*((Egam)./(me))).*((1)./(1+((Egam)./(me)).*(1-(1-(me)./(Egam).*((ECrit)./(Egam)) ...
./(1-(ECrit)./(Egam))))).^2-(1)./(1+2.*((Egam)./(me))).^2);
end
function sigma1 = s1(Egam,ECrit,sigmaT,me)
sigma1 = (3.*sigmaT)./(8).*((((Egam)./(me)).^2-2.*((Egam)./(me))-2)./(((Egam)./(me)).^3).*log((1+2.*((Egam)./(me))) ...
./(1+((Egam)./(me)).*(1-(1-(me)./(Egam).*((ECrit)./(Egam))./(1-(ECrit)./(Egam)))))));
end
Now I get an error for just the Gammasigma function
Not enough input arguments.
Error in test>Gammasigma (line 8)
Gs = (exp(-exp(-((log(Egam)+1.2)./(.8)))-((log(Egam)+1.2)./(.8))+1)).*s3(Egam,ECrit,sigmaT,me);
Error in test (line 3)
compton1 = vpaintegral(Gammasigma,Egam,15,30);
And now I am lost on that too. Egam should be the only variable needed for that function but I still have the 'not enough input' error.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by