How to use a matrix for the inline function?

조회 수: 4 (최근 30일)
Bumseok
Bumseok 2014년 4월 18일
댓글: Bumseok 2014년 4월 18일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2014년 4월 18일
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 2014년 4월 18일
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
Walter Roberson
Walter Roberson 2014년 4월 18일
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 2014년 4월 18일
I think it works. Great!! Thanks....

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by