Does anyone had this plotting problem with MATLAB?

In summary: Can you tell me what the problem is?The problem is that you are assigning y(:,i+1) = (y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h); which assigns one beyond the second dimension, tspan(end)/h, of y.Just as a quick test, you should increase the initialization dimension of y to y = zeros(6, tspan(end)/h + 1); and see if that solves anything.
  • #1
Cassius1n
13
0
I have finsihed my work on an orbit propagator in MATLAB and now I'm trying to simulate the orbit with the help of the main script.

tspan=[0 :860];

Position and velocity
y0(1,1)= 743322.3616 ;
y0(2,1)= -6346021.219 ;
y0(3,1)= -3394131.349 ;
y0(4,1)= 5142.38067;
y0(5,1)= 4487.44895 ;
y0(6,1)= -7264.00872;

%%%% Mass(kg) /surface(m^2)

m = 217 ; %320;
A = 1.2; %8;

%%%% RK4

h=1;
y = zeros(6, tspan(end)/h);
y(:,1) = y0;

for i=1:1:(tspan(end)/h)

H=sqrt(y(1,i)^2+y(2,i)^2+y(3,i)^2);
k_1 = proiectia(tspan(i), y(:,i), H, m, A, y(4:6, i));
k1=k_1;
k_2 = proiectia(tspan(i)+0.5*h, y(:,i)+0.5*h*k_1, H, m, A, y(4:6, i));
k2=k_2;
k_3 = proiectia((tspan(i)+0.5*h), (y(:,i)+0.5*h*k_2), H, m, A, y(4:6, i));
k3=k_3;
k_4 = proiectia((tspan(i)+h),(y(:,i)+k_3*h), H, m, A, y(4:6, i));
k4=k_4;

y(:,i+1) = (y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h);
plot3(y(1,:),y(2,:),y(3,: ));
drawnow

end
prp.png

The orbit is well described but it keeps drawing an extra line from 0 to where the point(x,y,z) is .After all the values are being represented, the line from 0 dissapears and it only remains the curved line(the orbit). Does anyone have any ideea why does it plot that line from 0 while is on the Runge Kutta loop?
 

Attachments

  • prp.png
    prp.png
    3.7 KB · Views: 521
Physics news on Phys.org
  • #2
It bothers me that your assignment of y(:,i+1) = (y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h); assigns one beyond the second dimension, tspan(end)/h, of y. Maybe that is causing a problem at the end of the plot of y. It would help us if you can tell us which end of y that zero point is. Is it at y(:,1) or at y(: tspan(end)/h)?
 
  • #3
That would be at at y(: tspan(end)/h).
 
  • #4
Just as a quick test, you should increase the initialization dimension of y to y = zeros(6, tspan(end)/h + 1); and see if that solves anything. You are making an assignment beyond the current dimension.
 
  • #5
It's still plotting with the line from 0.
 

What is a plotting problem in MATLAB?

A plotting problem in MATLAB refers to any issue or difficulty encountered while creating a visual representation of data using the MATLAB software. This could include errors, incorrect or incomplete plots, or difficulties in customizing the plot's appearance.

Why am I having a plotting problem in MATLAB?

There could be several reasons why you are having a plotting problem in MATLAB. Some common causes include errors in the code, incorrect data input, or compatibility issues with the version of MATLAB you are using.

How can I fix a plotting problem in MATLAB?

The solution to a plotting problem in MATLAB depends on the specific issue you are facing. Some general troubleshooting steps include checking for errors in the code, verifying the data input, and updating to the latest version of MATLAB.

Can I prevent future plotting problems in MATLAB?

Yes, you can prevent future plotting problems in MATLAB by following best practices for coding and data input. This includes checking for errors, using appropriate data types, and keeping your software up to date.

Should I seek help if I have a plotting problem in MATLAB?

If you are unable to resolve the plotting problem on your own, it is recommended to seek help from a more experienced MATLAB user or consult the official MATLAB documentation. You can also ask for assistance on online forums or reach out to the MATLAB support team for further assistance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
999
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
2
Replies
36
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
574
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top