![gravitational field equation solution in gnu octave gravitational field equation solution in gnu octave](https://media.cheggcdn.com/media/81b/81bd5ed5-9df4-4b57-8f00-19be043f360a/phpZ8WEDp.png)
- GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE HOW TO
- GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE FULL
- GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE CODE
GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE CODE
You can find the code I used to create these two plots bellow. Saving to an image file requires a little bit of effort though.
GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE FULL
You can find the full code of the examples in the text, under freefall_analytical.m and freefall_numerical.m. Plot(yv(:,1)*0,yv(:,1),"b.","markersize",15) Īs expected, the results are the same as before.Īs above, only this time position and velocity were computed numerically Code Having solved our system, we can proceed in plotting position and velocity as before. The solution - yv - is a matrix with two columns, corresponding to y and v, and with as many rows as the size of t, or in this time 21. Here t was defined in line 3 to be t=0.1:2. Time t should be a vector, and the first position of this vector - t(1) - should correspond to the time where the system is in the initial state. Lsode needs the function name, the initial state vector, and the time to solve for. Lsode_options("absolute tolerance",1e-30) %change the tolerance to get better results Let us first reduce the absolute tolerance though, to get the exact same results as previously. Now we can call lsode, to compute the solution. Notice how we were forced to put the acceleration inside the function (line 9). Lets name this vector yv, and its derivative dyv. For our particular case, we want to define a function where x(1) will represent position, and x(2) will represent velocity. This function should have the form xdot=f(x,t), where xdot stands for dx/dt, and thus have the same size as x. Octave can solve equations numerically, but for the solver to be able to call them at once, they should all be added in a single function. Only this time we can’t have acceleration defined here. We can start again by defining all the values of interest. Now lets try to produce the same results using a numerical solution. Left: Position of object with respect to time Middle: Velocity with respect to time Right: Position of the object every 0.1 sec. Plot(y_t(t)*0,y_t(t),"b.","markersize",15)Īll these plots can be seen in the figure bellow The easiest way to produce it to multiply y_t(t) with zero. To do so, we will need an x vector, equal in size with the y vector.
![gravitational field equation solution in gnu octave gravitational field equation solution in gnu octave](https://jsss.copernicus.org/articles/10/261/2021/jsss-10-261-2021-f04-web.png)
First we plot position, as a function of timeįollowed by velocity as a function of timeĪnd finally, we plot x and y position of the object every one tenth of a second - notice that t was first defined in line 4.
![gravitational field equation solution in gnu octave gravitational field equation solution in gnu octave](https://media.springernature.com/full/springer-static/image/art%3A10.1038%2Fs41598-021-81840-1/MediaObjects/41598_2021_81840_Fig1_HTML.png)
Now it is time to start plotting the variables of interest. %define the equations as anonymous functions To find x for a specific time t, we can now use x_t(t) To do that, we start by defining all the values of interestĪfter that, and to make the code more clear, we define y(t) and v(t) as anonymous functions. Now lets make some plots in octave, and see how this solution looks like. With that in mind, finding its velocity and position is just a matter of solving two differential equations. Newtonian physics dictates that, when one object falls freely, its acceleration is g. I will start with the analytical solution, and move forward to the numerical solution using octave.
GRAVITATIONAL FIELD EQUATION SOLUTION IN GNU OCTAVE HOW TO
Here I will try to give a simple example of doing so, by showing how to calculate the position and velocity of an object in free fall. But really unless you are in a production environment the time spent on further analysis is not really cost effective given how fast this executes as it is.Octave is a great tool for solving differential equations. It is quite obvious that the desired root is close to $x=170$, so starting with $0$ as the left hand limit for the bisection can be improved. The solution method can be improved somewhat if you send some time analysing the problem. If ff(a,Nknots)*y > tic,MyMain(100,1e-12),tocĬhanging from n=100 to n=10000 in Simpson's rule less than doubles the computational time required. So if I understand this correctly, we need to use Simpson's rule to evaluate $x_l$ where When $R=200$ and $L=170.$ Evaluate all the integrals by using the composite Simpson's rule. Use Matlab and numerical methods to find $x_l$ so that