Filter löschen
Filter löschen

Trying to make a loop for a definite integral

5 Ansichten (letzte 30 Tage)
Georgios Panagiotou
Georgios Panagiotou am 15 Sep. 2015
Beantwortet: Greig am 16 Sep. 2015
I am trying to create a loop for the following definite integral for y=0 to y=20 with step 0.01 in order to make a plot.any ideas are welcome

Antworten (1)

Greig
Greig am 16 Sep. 2015
Is something like this what you are after?
clear vars *;
% Define the function - Note I simplify the denominator in the last term
% Double check the numbers are typed correctly!
F =@(x) 2.906663106 .* x .* ( 1 ./(1 + 1.38 .* x.^4)).^0.4311594203...
- ( (3.458929096 .* x.^5) ./ (1 + 1.38 .* x.^4).^1.4311594203 );
% define teh Y values and the steps
Y = 0:0.01:20;
nSteps = length(Y);
% preallocate the integral values for speed
Ival = NaN(nSteps-1, 1);
% Do the loop
for ii = 1:nSteps-1
Ival(ii) = integral(F, Y(ii), Y(ii+1));
end
% Check it all adds up...
% The whole integral
integral(F, 0, 20)
% The sum of the parts
sum(Ival)
% Then add some plotting function here

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help 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