Integration using a loaded file

15 views (last 30 days)
Amy
Amy on 7 Mar 2014
Commented: Mike Hosea on 7 Mar 2014
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 Comment
Mike Hosea
Mike Hosea on 7 Mar 2014
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

Sign in to comment.

Answers (0)

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!