How to use a matrix for the inline function?
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
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()
0 个评论
Bumseok
2014-4-18
4 个评论
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()
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!