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

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!

Answers (1)

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 Comments

Hi Jyothis,
I tried this method and got two errors. First, when I tried to solve using vpa I get:
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
I tried to covert my results using:
l=double(dNdt);
which returned this error:
Error using symengine
Unable to convert expression into double array.
My code currently looks like:
function l = spectrum_sym(t,N)
[x,z,kbg,I,p]=deal([]);
syms('x','z','kbg(x)','I(x,z)','p(x,z)');
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 p= photons(x,z)
kbg= K * exp(-s*(x - 484));
I= Iin * exp((-Kw*z) -(kbg*z) -sum(k*N*z));
p=a*k*I;
end
y = int(p,x,400,700);
d= pmax * ((y/(pmax/phi)) + y) - L * N;
dNdt= (N/zm)* int(d,z,1,10);
l = vpa(dNdt);
l=double(dNdt);
end
Any insight on how to ger this to return a floating point value would be greatly appreciated.
Thanks,
Jake
What class() of value are t and N expected to be?
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

This question is closed.

Products

Release

R2019a

Asked:

on 13 Sep 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!