How to change ode45 from solution for range of values, to solution just for one value?

조회 수: 1 (최근 30일)
I have next function file:
function [f,R]=fun_z3(z,p)
beta=1;
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,:);
where I call it with
[zv, pv] = ode45(@fun_z3, [1 0], [1; 0; 0; 0]);
Now, I need to calculate pv, but just in case where zv=0 (in upper file zv=1:0), but for series of beta values. When I change boundaries for z, it means [1 0] to [0 0] or [0], I got some errors. Is it possible implement series of beta values just as range of values?

채택된 답변

madhan ravi
madhan ravi 2019년 1월 9일
Just parameterize function (lookup doc):
beta=....range of values
for beta = beta
ode45(@(z,p)fun_z3(z,p,beta), [1 0], [1; 0; 0; 0])]; % function call
end
function [f,R]=fun_z3(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
  댓글 수: 4
I G
I G 2019년 1월 14일
편집: I G 2019년 1월 14일
If I would like to change boundaries, in way that z is going from 0 to 1, now it is from 1 to 0, for what value of beta are my initial conditions, which are now [1; 0; 0; 0]?
Because in case when I am looking from back, from 0, I got different number of values for every cell of p, and that is not ok for me? What would I do to have constant number - constant dimension for p as soluton? Now it is 93x4 values, 97x4 values, 101x4 values, 105x4 values.
madhan ravi
madhan ravi 2019년 1월 14일
It would be [0 1] but honestly I have no idea why the p number of values vary in every iteraration.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by