Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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)

Jyothis Gireesh
Jyothis Gireesh on 16 Sep 2019
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
Jake Swanson
Jake Swanson on 2 Oct 2019
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

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!