hello
your errors are due to trying to access a structure in a wrong way , like :
I suppose the intention is to access the y output in this structure
so it should be :
but this is the second sample of the simulation, and I guess what you wanted is to have the last sample , 2nd row of the y array
xa = struct with fields:
solver: 'ode45'
extdata: [1×1 struct]
x: [1×889 double]
y: [6×889 double]
stats: [1×1 struct]
idata: [1×1 struct]
so I suppose this is the correct output :
but I am surprised to see very big numbers , and also the plot is a bit strange with only a straight line , so I wonder where we still have trouble with your code.
I also added "hold on" after your plot command as I guess you want to have all points of your loop being plotted
f=@(t,x) [x(2);x(3);2*x(2).^2+2*(x(2)*x(5))-x(1)*x(3)-x(3)*x(4)+M.^2*x(2)/(1+1./beta);
x(5);x(6);2*x(5).^2+2*(x(2)*x(5))-x(1)*x(6)-x(4)*x(6)+M.^2*x(5)/(1+1./beta)];
while err > err_threshold
xa=ode45(f,[0 10],[0 1 p1 0 0.3 0]);
xa=ode45(f,[0 10],[0 1 p2 0 0.3 0]);
plot([p1 p2],[m1 m2]);hold on
p2=(p2-p1)/(m2-m1)*(1.0-m1)+p1;
xa=ode45(f,[0 10],[0 1 p2 0 0.3 0]);