How to use a matrix for the inline function?

9 views (last 30 days)
Bumseok
Bumseok on 18 Apr 2014
Commented: Bumseok on 18 Apr 2014
I would like run integral function with respect to x. Also this equation contains t which is a matrix format.
t=load('E:\jul0520101_k_ascii.txt');
f1=inline('374040000/(3.14*(x.^5)*(exp(14387/(x.*t))))'); q=quad(f1, 9.6, 10.2);
I got the following error message.
??? Error using ==> inline.subsref at 14 Not enough inputs to inline function.
Error in ==> quad at 77 y = f(x, varargin{:});
Error in ==> flux_density at 7 q=quad(f1, 9.6,10.2);
Please let me know how to solve it.

Answers (2)

Walter Roberson
Walter Roberson on 18 Apr 2014
The string '374040000/(3.14*(x.^5)*(exp(14387/(x.*t))))' has two names coded into it, so inline() is going to build a function with two arguments. quad() is going to try to invoke that inline function with a single argument.
Remember, when you have a name inside a string, MATLAB is not going to substitute the value of a variable with that name.
You could use
q = quad(@(x) f1(x,t), 9.6, 10.2);
but you need to double-check whether inline is going to expect is arguments in the order x, t, or in the order t, x. Safer to tell inline the order you want the arguments to be.
Better yet would be to forget that inline functions exist and use anonymous functions instead.
f1 = @(x) 374040000/(3.14*(x.^5)*(exp(14387/(x.*t))));
will find the defined value of "t" just fine.
I'm not sure why you are using 3.14 when you could be coding pi ?
By the way, the vector that quad() passes into the function can vary in length between internal calls, so you really should not be counting on (x.*t) to be meaningful unless you are certain that the file contains exactly one value to be loaded into "t". What behavior were you hoping would result? If you are hoping to output a value for each combination of entries in "x" and "t" and have quad compute the numel(t) distinct integrations simultaneously, then that is not going to work. Perhaps you want to have a look at quadv()

Bumseok
Bumseok on 18 Apr 2014
Thanks, but still not working.
Let's suppose that t=[3 1 5 6 3; 3 9 8 5 7; 3 6 4 9 5; 0 1 3 7 9; 9 3 0 9 9]. Then, I changed a code as following yours.
I would like to calculate an integral function w.r.t x over the all t elements.
f1=@(x) 374040000/(pi*(x.^5)*(exp(14387/(x.*t)))); q=quad(f1(x) , 9.6,10.2);
Is it much clearer to guide me?
  4 Comments
Walter Roberson
Walter Roberson on 18 Apr 2014
You should be assigning to Qs(i,j)
If you are going to handle one t at a time then you should use quad() instead of quadv()
Bumseok
Bumseok on 18 Apr 2014
I think it works. Great!! Thanks....

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!