Error in Numerical Integration, "Matrix dimensions must agree"

I am analyzing dynamic behavior of helicopter blade.As a part of calculation, I need to integrate a function of 2 variables (time and geometry). To do it and in order to accelerate the calculation I use numerical integration which has done a perfect job for me solving ODE, but now , when I want to integrate any function of 2 variables using numerical integration, an error keeps popping. Below is an example of kinda functions that I am struggling with.
function myfun= test_integral(t)
myfun= integral(@f,0,10);
function fun=f(z)
fun= cos(z).*t;
end
end
__________________________________
When I call this function in command windows for t=( 'a single number' ) like 1, I get the correct answer , but when I try to plot it or get the results for a range of numbers, appears an error says that "Matrix dimensions must agree." :
>> test_integral(1)
ans =
-0.5440
>> t=linspace(0,10,20);
>> test_integral(t)
Error using .*
Matrix dimensions must agree.
Error in test_integral/f (line 6)
fun= cos(z).*t;
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 89)
Q = integralCalc(fun,a,b,opstruct);
Error in test_integral (line 3)
myfun= integral(@f,0,10);
I tried symbolic integration "int" which works for this case , but there are some functions in my calculations which are defined by interpolating some sets of data that cannot be integrated using symbolic integration.
Please Help me on this because my whole work is stuck here. Thanks.

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 25 Okt. 2013
function myfun= test_integral(t)
myfun= integral(@f,0,10,'ArrayValued',true);
function fun=f(z)
fun= cos(z).*t;
end
end

4 Kommentare

Thank you SO MUCH ! Where can I learn about these additional options of different intrinsic Matlab functions ??
MATLAB documentation
:-|
well... I still can't find anything in my Matlab Documantation that explains these thing.
Anyway , thanks again for your response ;)
Andrei Bobrov
Andrei Bobrov am 25 Okt. 2013
Bearbeitet: Andrei Bobrov am 25 Okt. 2013
Hi Ahmad! Your case in doc integral

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by