## Setting Boundary Conditions & Using bvp4c

Hi, I’m having trouble understanding how to use bvp4c. For my assignment, I have created a game that shoots a cannonball at a certain velocity and angle (which are the game inputs), it an attempt to hit a castle (the location is generated by the game).

Now, I need to make a cheat script using bvp4c that when given the position of the castle, outputs a set of velocity and angle values that would make the cannonball hit the castle. The castle is the red square in the image.

sol = = bvp4c(@gamePhysics,@bcfun,solinit)

Here are the two second order ODE’s that describe projectile’s motion:

From there I converted them to these four first order ODE’s:

function dydt = gamePhysics(t,y)

m = 5; % kg

D = 0.013; % N*s^2/m^2

g = 9.81; % m/s^2

dydt = zeros(4,1);

dydt(1) = y(2)

dydt(2) = ((-D/m)*y(2)*(y(2)^2+y(4)^2)^(0.5));

dydt(3) = y(4);

dydt(4) = ((-g)-(D/m)*y(4)*(y(2)^2+y(4)^2)^(0.5));

end

I’m now stuck on making a function that describes the boundary conditions. At the origin, y(0) = 0 and at the castle, y(0) = x_castle.

Also, I’m confused on what the solinit function in bvp4c means. Am I guessing a random velocity and angle?

Thank you! Sorry, I’m pretty lost on how to use this function.Hi, I’m having trouble understanding how to use bvp4c. For my assignment, I have created a game that shoots a cannonball at a certain velocity and angle (which are the game inputs), it an attempt to hit a castle (the location is generated by the game).

Now, I need to make a cheat script using bvp4c that when given the position of the castle, outputs a set of velocity and angle values that would make the cannonball hit the castle. The castle is the red square in the image.

sol = = bvp4c(@gamePhysics,@bcfun,solinit)

Here are the two second order ODE’s that describe projectile’s motion:

From there I converted them to these four first order ODE’s:

function dydt = gamePhysics(t,y)

m = 5; % kg

D = 0.013; % N*s^2/m^2

g = 9.81; % m/s^2

dydt = zeros(4,1);

dydt(1) = y(2)

dydt(2) = ((-D/m)*y(2)*(y(2)^2+y(4)^2)^(0.5));

dydt(3) = y(4);

dydt(4) = ((-g)-(D/m)*y(4)*(y(2)^2+y(4)^2)^(0.5));

end

I’m now stuck on making a function that describes the boundary conditions. At the origin, y(0) = 0 and at the castle, y(0) = x_castle.

Also, I’m confused on what the solinit function in bvp4c means. Am I guessing a random velocity and angle?

Thank you! Sorry, I’m pretty lost on how to use this function. Hi, I’m having trouble understanding how to use bvp4c. For my assignment, I have created a game that shoots a cannonball at a certain velocity and angle (which are the game inputs), it an attempt to hit a castle (the location is generated by the game).

Now, I need to make a cheat script using bvp4c that when given the position of the castle, outputs a set of velocity and angle values that would make the cannonball hit the castle. The castle is the red square in the image.

sol = = bvp4c(@gamePhysics,@bcfun,solinit)

Here are the two second order ODE’s that describe projectile’s motion:

From there I converted them to these four first order ODE’s:

function dydt = gamePhysics(t,y)

m = 5; % kg

D = 0.013; % N*s^2/m^2

g = 9.81; % m/s^2

dydt = zeros(4,1);

dydt(1) = y(2)

dydt(2) = ((-D/m)*y(2)*(y(2)^2+y(4)^2)^(0.5));

dydt(3) = y(4);

dydt(4) = ((-g)-(D/m)*y(4)*(y(2)^2+y(4)^2)^(0.5));

end

I’m now stuck on making a function that describes the boundary conditions. At the origin, y(0) = 0 and at the castle, y(0) = x_castle.

Also, I’m confused on what the solinit function in bvp4c means. Am I guessing a random velocity and angle?

Thank you! Sorry, I’m pretty lost on how to use this function. bvp4c, boundary conditions, ode45 MATLAB Answers — New Questions