Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Not Enough Input Arguments when trying to pass two variables as undefined

1 回表示 (過去 30 日間)
Jake Swanson
Jake Swanson 2019 年 9 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function l = spectrum(t,N)
%parameters
pmax= 1;
phi= 2 * 10^12;
L= 0.67;
a= 1;
k= 1;
Iin= 100;
Kw= 2;
s= 0.017;
zm= 10;
K=1;
function j= photons(x,z)
kbg= K * exp(-s*(x - 484));
I= Iin * exp((-Kw*z) -(kbg*z) -(k*N*z));
j=a*k*I;
end
y = integral (@photons,400,700);
function d = growth (z)
d= pmax * ((y/(pmax/phi)) + y) - L * N;
end
dNdt= (N/zm)* integral(@growth,0,10);
l = dNdt
end
I'm trying to recreate the differential equations in the attached PDF but when I try to use ode45 to solve I'm receiving an error "Not enough input arguments" in line 19 (equation I within function j). If I define either x or z as some value then the code works but I need both x and z to be undefined because I need to integrate over x from 400 to 700 and over z from 0 to 10. I tried defining x and z as elements of an array Y, but that returned "Index exceeds number of array elements (1)" as an error.
I don't think this code is optimized in any way but I'm mainly curious as to how I can get x and z to be accepted as undefined variables in order to eventually integrate over them. Any help or advice would be appreciated!

回答 (1 件)

Jyothis Gireesh
Jyothis Gireesh 2019 年 9 月 16 日
Here are a few pointers which may help in solving this issue:
  • Currently the numerical integration function in MATLAB accepts only function handles with one input argument. You may make use of the concept of nested functions or anonymous functions as a workaround for this difficulty.
  • But the above option may not be the correct approach in this case as the output of photon() should be a function of z”. It may be better to redefine the equations using symbolic variables using the Symbolic Math Toolbox which allows the integration of multivariable expressions with definite integrals.
Please try using the following methodology
  • Define "x" and "z" as symbolic variables in spectrum()
  • Define "kgb", "I" and "j" as symbolic functions involving two symbolic variables x and z
  • Integrate "j" using
y = int (j, x, 400, 700)
This is a definite integral with x as independent variable and limits from 400 to 700.
  • Use the following code to get the result.
dNdt = (N/zm)*int(d,z,0,10); %Integrating wrt z from 0 to 10
l = vpa(dNdt);
Please refer to the following link for further information on usage of symbolic variables and “int()”
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 30 日
What class() of value are t and N expected to be?
Jake Swanson
Jake Swanson 2019 年 10 月 2 日
t is a timespan from 0 to 100 while N represents a starting value of 100 so I think they should both be of class double

この質問は閉じられています。

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by