Numerical integration in matlab2018

Dear Friends,
This looks simple but am not able to get it. Could you help me out.
I have the following variable in a equation that needs to be integrated
its like
L = linspace(0.3,4.5,2000);
T = 100;
fun = @(T) ((0.4175./L.^3) - (0.6643./L.^2) + (0.9036./L) + 3.5332 - 0.0744.*L).*10^-5.*(1 + 0.00276.*T);
q = integral(fun,20,T)
However, when i rum this, iam getting an error. Could you help me out on solving this.

3 Comments

Adam Danz
Adam Danz on 22 Apr 2019
Edited: Adam Danz on 22 Apr 2019
The integral() function evaluates your function between x=20 and x=100 (your inputs) and expects to receive a single value as an output for each input. It then computes the integral under that curve.
Your function is returning a vector of outputs 2000 elements long for each input.
I dint get you completely...
Do i need to use a for loop for this kind of integration?
Check out these examples provided by matlab (link below). When you evalue the functions in those example, you'll see that they return a single value.
When I evaluate your function, a vector is returned:
>> fun(20)
ans =
Columns 1 through 6
0.00015411 0.00015159 0.00014914 0.00014676 0.00014444 0.0001422
Columns 7 through 12
0.00014002 0.0001379 0.00013584 0.00013383 0.00013189 0.00012999
Columns 13 through 18
0 ...... (2000 elements long)
Did you expect that your function returns a single value or do you expect that it returns a vector?

Sign in to comment.

Answers (0)

Products

Asked:

on 22 Apr 2019

Commented:

on 22 Apr 2019

Community Treasure Hunt

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

Start Hunting!