I am trying to do the following:
t = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]; %time = 1x20
heatflux = [2 3 5 7 9 11 12 13 14 19 24 14 12 13 20 21 11 23 18 19]; %heatflux = 1x20
fun = @(t) (heatflux).*t;
energy = integral (fun,0,20);
And I get this error:
Matrix dimensions must agree.
Error in HeatFlux>@(t)(heatflux).*t
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in HeatFlux (line 22)
energy = integral (fun,0,20)
Can someone point what I am doing wrong? Both t and heatflux have the same matrix dimension 1x20!

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 1일
편집: Andrei Bobrov 2017년 6월 1일

3 개 추천

>> t = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]; %time = 1x20
heatflux = [2 3 5 7 9 11 12 13 14 19 24 14 12 13 20 21 11 23 18 19]; %heatflux = 1x20
energy = trapz(t,heatflux)
energy =
259.5000
>>

댓글 수: 3

Torsten
Torsten 2017년 6월 1일
energy = trapz(t,heatflux);
Best wishes
Torsten.
Fotis_oe
Fotis_oe 2017년 6월 1일
Perfect! Thanks!
Andrei Bobrov
Andrei Bobrov 2017년 6월 1일
Thank you Torsten!
This my typo. I'm corrected.

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

추가 답변 (1개)

Torsten
Torsten 2017년 6월 1일

1 개 추천

Use "trapz".
Best wishes
Torsten.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2017년 6월 1일

댓글:

2018년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by