//Question: Before interpolation the A matrix data i was unable to execute it because it was throwing error like A(2.6) for diffrent n(always integer) integers. Then i tried interpolating my matrix A . Its not giving proper results. Also i want my final answer to be displayed after for loop
t = 1 : 9;
t1= 1 : 0.1: 9;
A = [916.3 , 923.6 , 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3];
A1= interp1( t , A, t1 , 'nearest');
a=1;
b=9;
n=6;
h=(b-a)/n;
for i = 0:3
ans =0.5*[A1*(a+(i*h)) + A1(a+(i+1)*h)]*h;
end

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 6 日
編集済み: Azzi Abdelmalek 2013 年 11 月 6 日

0 投票

This line A1= interp1( t , A, t1 , 'nearest') is not correct, t is not defined, use
A1= interp1( time , A, t1 , 'nearest')
Add
a = 1;
b = 9;
n = 4;
h = (b-a)/n;
A = [916.3, 923.6, 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3 ];
for i = 0:3
res = 0.5 * [ A(a+(i*h)) + A(a+(i+1)*h) ]*h;
disp(res)
end

8 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 6 日
編集済み: Azzi Abdelmalek 2013 年 11 月 6 日
A(2.6) is not correct, the index should be a positive integer or logical.
If you want the value of A1 for t1=2.6,
A1(t1==2.6)
Rizwana
Rizwana 2013 年 11 月 6 日
編集済み: Rizwana 2013 年 11 月 6 日
Hi: That was my typing mistake. Iam still getting not so correct value. Before interp1 function program is shown below: here the for loop executed 3 times and it displayed results because i have hand calculations it was matching. But this code was not working with variable n integers. Now iam not getting proper answer when i use interpolation
a = 1;
b = 9;
n = 4;
h = (b-a)/n;
A = [916.3, 923.6, 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3 ];
for i = 0:3
ans = 0.5 * [ A(a+(i*h)) + A(a+(i+1)*h) ]*h
disp('ans')
end
Thank You
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 6 日
a = 1;
b = 9;
n = 4;
h = (b-a)/n;
A = [916.3, 923.6, 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3 ];
for i = 0:3
res = 0.5 * [ A(a+(i*h)) + A(a+(i+1)*h) ]*h;
disp(res)
end
Rizwana
Rizwana 2013 年 11 月 6 日
編集済み: Rizwana 2013 年 11 月 6 日
this wont work when i change n value to 5 or 6 or some other value also o/p is something like this:
res=
1.8494 e+003
1.8494 e+003
res=
1.8993e+003
1.8993e+003
res=
1.9747e+003
1.9747e+003
res=
2.059e+003
2.059e+003
// instead of multiple results i would like to have one res showing:
res=(1.8494 e+003)+(1.8993e+003)+(1.9747e+003)+(2.059e+003)
Thank You
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 6 日
編集済み: Azzi Abdelmalek 2013 年 11 月 6 日
%If a+(i*h)) and a+(i+1)*h represent time
a = 1;
b = 9;
n = 5;
h = (b-a)/n;
t = 1 : 9;
A = [916.3, 923.6, 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3 ];
for i = 0:3
res=0.5*h*(interp1(t,A,a+i*h)+interp1(t,A,a+(i+1)*h));
disp(res)
end
Rizwana
Rizwana 2013 年 11 月 6 日
Here the matrix A represents presure quantities at time 1 to 9... i.e; A(1)=916.3---> presurre recorded at time 1sec A(2)=923.6---> presure recorded at time 2 sec... when i change n value to 5; then A in my program becomes A(1.6) This is throwing error... Hence i splitted the time array from 1:0.1:9 then interpolated the presuure data i.e ; A matrix to these values... Tried coding using program... Not getting answer with interpolated values... I tried to run your program.. Its throwing error: subscript indices must be real positive or logical... Thank You
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 6 日
I don't think you tried the correct program, copy ant paste the code in my previous comment. It works without errors
Rizwana
Rizwana 2013 年 11 月 6 日
Thank You so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

タグ

質問済み:

2013 年 11 月 6 日

編集済み:

2013 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by