The result is not what I want it is completely different ,,so Is there anyone could help me to use another routines to get the result for this code please?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
This code what I am doing,, My problem is in plot(4),The result is not what I want it is completely different ,,so Is there anyone could help me to use another routines to get the result for this code please?
function Runfisher
A=1;
b=3;
x0=[12 5];
dt=0.01;
tspan=0:dt:1;
[t,x]=ode45(@fisher,tspan,x0,[],b);
figure(1)
plot(t,x)
figure(2)
plot(x(:,1),x(:,2),'-')
grid
dt= 0.095;
a1 = ( 15*x(1) - b*x(1).*x(2) );
b1 = ( -5*x(2) + 0.5*x(1).*x(2) );
I = A.*(dt.^2).*sum.*( ( ( ( (a1.*(15-b*x(2))+b1.*(.5*x(2))).*a1 ) + ( (a1.*(-b*x(1))+ b1.*(-5+.5*x(1))).*b1) ).^2)./(( (a1.^2) + (b1.^2) ).^2) )
ball=2:1:10 ;
n = length(ball) ;
Iall = zeros(1,n) ;
for i = 1 : n
[t,x]=ode45(@fisher,(0:0.0001:1),x0,[],ball(i)) ;
figure(3)
plot(x(:,1),x(:,2))
hold on
dt= 0.095;
a1 = ( 15*x(1) - ball(i).*x(1).*x(2) );
b1 = ( -5*x(2) + 0.5*x(1).*x(2) );
I = A.*(dt.^2).*sum.*( ( ( ( (a1.*(15-ball(i).*x(2))+b1.*(.5*x(2))).*a1 ) + ( (a1.*(-ball(i).*x(1))+ b1.*(-5+.5*x(1))).*b1) ).^2)./(( (a1.^2) + (b1.^2) ).^2) ) ;
Iall(i) = I
end
figure(4)
plot(ball,Iall,'r-')
1;
% function dxdt = fisher(t,x,b)
% dxdt=zeros(2,1);
% dxdt(1) = 15 * x(1) - b * x(1).* x(2);
% dxdt(2) = -5 * x(2) + .5 * x(1).* x(2);
% end
The right plot for figure(4) should increase until (ball =3 ) then it will deceasing until the last value. But what I am getting is just increasing line . I do not what is the reason so could anyone help me please?
13 Comments
Torsten
on 4 Nov 2014
Questions:
1. What is the value of the variable "sum" in the calculation of I ?
2. x is an (nx2) matrix where n is the number of output times from ODE45.
So what are x(1) and x(2) in the calculation of I ?
3. Why is the function "fisher" commented out ?
Best wishes
Torsten.
Avan Al-Saffar
on 5 Nov 2014
Edited: Avan Al-Saffar
on 5 Nov 2014
Torsten
on 5 Nov 2014
ad 1) "sum" is a MATLAB operator that sums elements of arrays or matrices.
So "sum.*" has to be replaced simply by "sum".
ad 2)
I guess "I" should contain an approximation of an integral over time.
Thus you will have to replace
x(1) by x(:,1),
x(2) by x(:,2),
a1 = ( 15*x(1) - ball(i).*x(1).*x(2) ); by a1(:) = ( 15*x(:,1) - ball(i)*x(:,1).*x(:,2) );
and
b1 = ( -5*x(2) + 0.5*x(1).*x(2) ); by b1(:) = ( -5*x(:,2) + 0.5*x(:,1).*x(:,2) );
Of course I don't know whether the function to be integrated is correct and whether the approximation of the integral by your sum is correct.
Best wishes
Torsten.
Avan Al-Saffar
on 5 Nov 2014
Torsten
on 5 Nov 2014
I don't know why, but the setting of a1, b1 and I appear twice in your code (at the beginning and in the for-loop). Furthermore, since tspan changes, the dimensions of a1 and b1 will be different at both positions of your code. So the easiest way is to start your code from the line
ball=2:1:10;
and delete the upper part.
Best wishes
Torsten.
Avan Al-Saffar
on 5 Nov 2014
Avan Al-Saffar
on 5 Nov 2014
Edited: Avan Al-Saffar
on 5 Nov 2014
Torsten
on 5 Nov 2014
Could you show the code you are using now ?
Best wishes
Torsten.
Avan Al-Saffar
on 5 Nov 2014
Torsten
on 5 Nov 2014
I get the attached output for Iall.
Best wishes
Torsten.
Torsten
on 5 Nov 2014
With an analogue Fortran-program, I get the following output for Iall:
ball Iall
2.00000000000000 1.65285396632246
3.00000000000000 2.03520968157525
4.00000000000000 3.46914314988618
5.00000000000000 6.11508746765178
6.00000000000000 9.82670128843249
7.00000000000000 14.5325924533958
8.00000000000000 20.1308960907625
9.00000000000000 25.9469750868376
10.0000000000000 31.4212066754488
Best wishes
Torsten.
Torsten
on 5 Nov 2014
Sorry, the numbers on the right should be one order of magnitude smaller (I divided by 1000, not by 10000).
Best wishes
Torsten.
Avan Al-Saffar
on 5 Nov 2014
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!