How can I shrink the time of getting the results please?

조회 수: 1 (최근 30일)
Avan Al-Saffar
Avan Al-Saffar 2015년 5월 28일
댓글: Avan Al-Saffar 2015년 6월 9일
I run the following code for 13 days until I got the results so could anyone advise me if there is any truck that I can use to shrink the time please? Because I need to run the code for different values!
function FisherN01analyticalsmallomega
y0=1;
a=1
c=50;
b = 2.5
t =(0:0.1:10000);
y = logisticOscilanalytical(t,c,y0,b,a);
Y = @(T) interp1(t,y,T);
g = @(t) ( (b.*sin(b.*t) + cos(b.*t).* (2.*Y(t)./c)).^2./(a.^2.*sin(b.*t).^3 .* (Y(t) - (Y(t).^2).^2))) );
t= (0:10:10000);
N = length(t);
JT = zeros(1,N);
for i = 1:N
JT = integral(g,0,t(1,i),'ArrayValued',true);
end
figure(1)
plot(t,JT,'-','LineWidth',2)
1;
% function y = logisticOscilanalytical(t, c, y0, b, a)
% ee = exp( (a/ b) * (1- cos( b*t)));
% y = (-c.* y0.* ee)./ ( (y0 - c) - y0.* ee);
% end
  댓글 수: 2
Jan
Jan 2015년 5월 28일
I've formatted the code, because it was not readable. Please use the "{} Code" button. Do not post code which is commented out - this confuses the readers.
Avan Al-Saffar
Avan Al-Saffar 2015년 5월 28일
Many thanks and sorry.

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

채택된 답변

Mike Hosea
Mike Hosea 2015년 6월 1일
편집: Mike Hosea 2015년 6월 1일
That code never gave you results because it isn't working--there is a syntax error. Specific suggestions are therefore hard to provide. Some more or less generic suggestions would be:
  • Debug your code using a smaller t range.
  • Avoid the 'ArrayValued' option unless your function is really array-valued. Using that option with a scalar-valued problem avoids the need to make your integrand handle array inputs, but it slows INTEGRAL significantly. If only compensating for an integrand that can't handle array inputs (and ONLY if the integrand can't handle array inputs), consider using ARRAYFUN, e.g. integrate
g1 = @(t)arrayfun(g,t);
  • If you're going to use an interpolated function (this will affect accuracy negatively), supply the abscissas as 'Waypoints'. In this example you'll need to save the original t values (they are overwritten in the supplied code).
q = integral(g1,a,b,'Waypoints',t);
  • If you want to generate a table of results, consider only integrating between the tabulated points and adding to an accumulator variable as you go, i.e.
JT = zeros(1,N);
s = 0;
for i = 2:N
q = integral(g,t(1,i-1),t(1,i));
s = s + q;
JT(i) = s;
% The above could be JT(i) = JT(i-1) + q; to do without s.
end
  • It looks like your integrand has a singularity when sin(b*t) == 0. You'll have to integrate between those values. Unfortunately, they can't just be 'Waypoints', and there is no guarantee that INTEGRAL will be able to handle the singularity.
  댓글 수: 1
Avan Al-Saffar
Avan Al-Saffar 2015년 6월 9일
Many thanks, your suggestion about 'Waypoints' solve my problem completely.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by