Solve MATLAB Homework: Find x1|t=0 for q=0.45

  • Thread starter Thread starter dugironbeard
  • Start date Start date
  • Tags Tags
    Matlab Stuck
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB homework problem involving a system of differential equations. Participants are tasked with determining the initial condition x1|t=0 that results in a known velocity magnitude q=0.45 at t=10. The conversation includes attempts to solve the problem using numerical methods and the shooting method.

Discussion Character

  • Homework-related
  • Mathematical reasoning
  • Technical explanation

Main Points Raised

  • The original poster presents a system of differential equations and initial conditions, seeking to find x1|t=0 that leads to a specific velocity magnitude at a later time.
  • One participant suggests using the "shooting method" to perturb the initial conditions and find the correct value for x1|t=0 that results in the desired outcome.
  • Another participant clarifies the concept of perturbation, explaining it as a change in the initial condition to explore how it affects the outcome.
  • The original poster expresses uncertainty about implementing the shooting method in MATLAB, indicating a need for further guidance on coding it.
  • A later post mentions finding initial values between 1.15 and 1.25 but struggles with coding the approach due to having multiple files for the calculations.

Areas of Agreement / Disagreement

Participants generally agree on the approach of using the shooting method, but there is no consensus on the specific implementation details in MATLAB. The discussion remains unresolved regarding the exact coding steps needed to achieve the solution.

Contextual Notes

Participants express varying levels of familiarity with MATLAB and the shooting method, indicating potential gaps in understanding how to apply the method effectively. There are also references to the need for a root search algorithm, but specific mathematical steps remain unclear.

dugironbeard
Messages
4
Reaction score
0

Homework Statement



dx(1)/dt=-0.1x(1)-x(2)
dx(2)/dt=x(1)-0.1x(2)

x1|t=0 = 1 , x2|t=0 =0

First we had to define the magnitude (q) of the velocity vector at t = 10.

The follow up question is:

The horizontal component x1|t=0 of the starting position is not known very accurately. However at t = 10 an accurate measurement of q=0.45 is known.

Determine the vvalue of x1|t=0 that leads to q=0.45

Homework Equations





The Attempt at a Solution




To find the initial q I made the following files in matlab.
clear,clc

x0=[1 0];
tspan=[0 1.01 10];
[t,x]=ode45('partb',tspan,x0);

x =

1.0000 0
0.4807 0.7656
-0.3083 -0.2002


function xp = partb(t,x)
t=10
x(1)=-0.3083
x(2)=-0.2002
xp(1)=(-0.1*x(1)-x(2));
xp(2)=(x(1)-0.1*x(2));
disp (xp(1))
disp (xp(2))
q=((xp(1)^2)+(xp(2)^2))^0.5
end

q = 0.3694

Now the problem is I don't know how to work backwards, I know I have to do something with fzero but I have to many variables. Any help would be greatly appreciated.
 
Physics news on Phys.org
It's called the "shooting method". You need to perturbate the initial conditions (IC's) to search for the correct IC to get x1(10)=0.45.

Start by finding one IC that gives x1(10)<0.45 and one other that gives x1(10)>0.45 then just narrow it down using a "root search" algorithm of your choice, though for simplicity I recommend using "halving the interval".

Note that you have already found one IC that leads to x1(10)<0.45. So now just perturbate x1(0) to find an IC that leads to x1(10)>0.45 and you're good to start halving the interval.
 
Thanks a lot for your reply uart.

Alright so first I am going to make a IC greater than 0.45. And than I have to write a root search algorithm.

Secondly really stupid maybe (English is not my native language), what is perturbate?
 
dugironbeard said:
Thanks a lot for your reply uart.

Alright so first I am going to make a IC greater than 0.45. And than I have to write a root search algorithm.

Secondly really stupid maybe (English is not my native language), what is perturbate?

It was probably not quite the right word. I wish I could claim that English was not my native language. :redface: A perturbation in this context is just a "change in" or a disturbance in the initial condition. In other words just try x1(0) either a bit more than one or a bit less than one and see which way x1(10) moves. Once you get it moving in the correct direction then keep going until you get to x1(10) > 0.45, then you are ready to start halving the interval.

If you like you can initially just do the "halving the interval" manually, making a run of the DE simulation, calculating the new IC (halfway between the current two closest that are located on alternate sides of x1(10)=0.45) and then taking another run etc. You should be able to get an approximate solution fairly quickly like this. One you get the hang of what's happening then you can write some code to implement this "shooting method" automatically.
 
Alright,

Well I am going back in tomorrow. Ill google a bit how to make a script for this shooting method.
 
Right, next day.

I have found the initial values of between 1.15 and 1.25. Now to be honest I understand the intention of the shooting method but I have no clue whatsoever how to write it into a MATLAB code. Problem is I have two different files, one with the initial ode45 and the next one that takes it and calculates a velocity vector.

What I have now and not working:
clear,clc
a=1.20:0.0001:1.25
x0=[a 0];
tspan=[0 1.01 10];
[t,x]=ode45('partb',tspan,x0);
 
Last edited:

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
1
Views
4K