Integration using a loaded file

1 次查看(过去 30 天)
Amy
Amy 2014-3-7
Hi
I want to solve the integration of (delta/A^2) between 0 and 0.9999999.
Delta and A^2 are arrays I have saved as txt files.
Am I able to load these files and then solve the integral? I have tried the following:
>> load 'fname.txt'
>> load 'fname2.txt'
>> f1 = inline('fname2.txt./fname.txt');
>> Q = quad(f1,0,0.9999999)
with the following error being thrown up:
Error using inline/subsref (line 13)
Not enough inputs to inline function.
Error in quad (line 72)
y = f(x, varargin{:});
I also tried
>> int(('fname2.txt/fname.txt'),0,0.9999999)
with no luck.
Thanks
  1 个评论
Mike Hosea
Mike Hosea 2014-3-7
You want to integrate an array of constants between 0 and 0.9999999? What is your variable of integration?
A few quick points, however:
Since your data is saved in text files, the load command will load them as the name of the file but without the extension, so after the load commands, your matrices are named fname2 and fname (leave off the .txt).
QUAD and INLINE are both obsolete. Here is an example of an array-valued integral:
>> A = [1,2,3;4,5,6;7,8,9]
A =
1 2 3
4 5 6
7 8 9
>> Q = integral(@(x)A*sin(x),0,pi,'ArrayValued',true)
Q =
2.000000000000000 4.000000000000001 6.000000000000000
8.000000000000002 10.000000000000000 12.000000000000000
14.000000000000000 16.000000000000004 17.999999999999996
If your copy of MATLAB is very old, you can do it with QUADV:
>> Q = quadv(@(x)A*sin(x),0,pi)
Q =
1.999999999943948 3.999999999887895 5.999999999831843
7.999999999775790 9.999999999719739 11.999999999663686
13.999999999607633 15.999999999551580 17.999999999495529

请先登录,再进行评论。

回答(0 个)

类别

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