How could I plot this function ( I =A* sum( ( (dt.^2)*(B.^2) )/(C.^2) ) with time please? I am getting just a constant line while I expect to get a curve because it is a function of time.

I am working with this code but it does not give me the result that I expect :
function RunFisherfixedb
x0=[12 5];
dt = 0.055;
t=(0:dt:1);
n=length(t);
Iall=zeros(1,n);
for i = 1:n
I = Fisherfixedb(t,x0,A,dt);
Iall(i)=I;
end
figure(01)
plot(t,Iall,'k')
xlabel('Time')
ylabel('Fisher Information')
title('Average Fisher information in Two-species predator-prey model')
1;
% function I = Fisherfixedb(t,x,A,dt)
% a1 = 15*x(1) - 3*x(1)*x(2);
% b1 =-5*x(2) + 0.5*x(1)*x(2);
% C= (a1.^2) + (b1.^2);
% B = ( (a1.*(15-3*x(2))+b1.*(.5*x(2))).*a1 ) + ( (a1.*(-3*x(1))+ b1.*(-5+.5* x(1))).*b1);
% I = A*sum( (dt.^2)*((B.^2)/(C.^2)));
end

5 Comments

Hi
Would you please tell us what is the problem?
Do you get any errors? if so please let us know.
There's no variable A defined in the function prior to calling Fisherfixedb altho w/o the source code for that function it's not possible to know for sure what that would do it's a fair assumption that that is a problem...
Also, in the plot statement you've use the intermediary variable I returned by the function which after the loop will only be the last value returned. I'd presume since you're plotting against (and the question title refers to) t that you intended that to be
plot(t,Iall,'k')
instead. Presuming, of course, take care of the arguments to the function so it works as intended.
Also, it's not at all clear what part B and C are to play in the overall scheme of things but since they're functions of two x values, neither of which is x0, nothing's going to happen with them in the code as given. That would be a surface plot and meshgrid is often most useful for such. See the example in
doc meshgrid
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 Runsystem
A=1;
b=3;
x0=[12 5];
dt=0.01;
tspan=0:dt:1;
[t,x]=ode45(@system,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).*( ( ( ( (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(@system,(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).*( ( ( ( (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 = system(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
What is the result you see, and the result you expect?
Unfortunately, we can't test your function, since you haven't shown the code for the (badly named) system function.
Note that you may be better off starting a new question as most people won't be looking at a question that has been marked as answered. If you do that, pleas use the {} code button to format your code.
I posted a new question so could you have a look please?

Sign in to comment.

 Accepted Answer

t is not used by your function Fisherfixeddb and all the other terms are constant, so of course, you get a constant line.
Fix your function to use t.
Note that you probably have a warning in the editor window precisely telling you that t is unused. Warnings are useful.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!