How to change number of steps of solutions with ode45 - Matlab?

223 Views Asked by At

I have the next function:

function [f,R]=fun_z_proba(z,p,beta)  % function definition
ri=0.7;
R=ri-z*(ri-1);
f=zeros(4,size(p,2));
f(1,:)=-32.*beta./(R.^4.*p(1,:));
f(2,:)=(-8*f(1,:)./R-f(1,:).*p(2,:))./p(1,:);
f(3,:)=(-p(2,:).*f(2,:)-8.*f(2,:)./R-8.*f(1,:)./(R.*R.*p(1,:))-f(1,:).*p(3,:))./p(1,:);
f(4,:)=(-f(2,:).*p(3,:)-f(3,:).*p(2,:)+8.*(-f(3,:)./R-   (f(2,:)./p(1,:)-p(2,:).*f(1,:)./(p(1,:).*p(1,:)))./(R.*R))    -f(1,:).*p(4,:))./p(1,:);
end

and I am calling it with

beta=1:0.1:5;
f=cell(1,numel(beta)); 
ctr=1; 
for beta = beta
[f{ctr},p{ctr}]=ode45(@(z,p)fun_z_proba(z,p,beta), [1 0], [1; 0; 0; 0]);
ctr=ctr+1;
end

Results important for me are stored in p, but for every value of beta I got different number of values for p. Is there some way to get the same number of p values in every case for beta, under the same conditions like here?

1

There are 1 best solutions below

0
On BEST ANSWER

If you want values at fixed locations, call the method with these locations in the place of tspan.

You could also use the dense output option to have an interpolation function over the whole interval. See Matlab documentation how to invoke it and use its result.