Need help while defining ode function for bvp4c/bvp5c/ode45 solve (2024)

Md Sojib about 8 hours ago

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve

Commented: Torsten about 2 hours ago

I wanted to define system of ode functions for my higher order problems. I have differential equations are :

x=cosy

z=siny

y'=sqrt((lambda*f*p*siny/x)+(siny^2/x^2)-(2/lambda^2)+(2*cosy/lambda)-(3*a*p^2*lambda^2/2))

y"=(-y'*x'/lambda*x)-(cosy/x)-(f*p'/4)-(f*x'*p/4*x)+(y'*cosy/x)+(siny/lambda)+(lambda*f*p*cosy/4*x)+(siny*cosy/x^2)+(mu_1*(sin(y) - mu_2*cos(y)) / (2 * x^2)

where, y,x,p are functions of s. and f,lambda and a are constants.

while defining ode function for my bvp solve, I write the code as

function dydx = odefun2(t, y, params)

lambda = params.lambda;

a = params.a;

f = params.f;

mu_1=params.mu_1;

mu_2=params.mu_2;

y1 = y(1); % y

y2 = y(2); % x

y3 = y(3); % z

y4 = y(4); % p

y5 = y(5); % p_dot

y6 = cos(y1); %x_dot

y7 = sin(y1); %z_dot

ydot = sqrt((lambda * f * y4 * sin(y1) / y2) + (sin(y1)^2 / y2^2) - (2 / lambda^2) + (2 * cos(y1) / lambda) - (3 * a * (y4^2) * lambda^2)/2);

yddot = -((ydot * cos(y1) / (lambda * y2))) - (cos(y1) / y2) - (0.5 * y5 / 4) - (0.5 *cos(y1) * y4 / (4 * y2)) + (ydot * cos(y1) / y2) + (sin(y1) / lambda) + (0.5 * lambda * y4 * cos(y1) / (4 * y2)) + (sin(y1) * cos(y1) / y2^2) + (mu_1*(sin(y1) - mu_2*cos(y1)) / (2 * y2));

dydx = [y5; y6; y7; ydot; yddot];

end

But I have no equation for p'. And I am not sure that how can I relate x and z with x' and z' respectively. Also I don't have any differential equation for p'. how I should relate p and p'?

need some suggestions.

11 Comments

Show 9 older commentsHide 9 older comments

Torsten 3 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180711

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180711

Edited: Torsten less than a minute ago

Open in MATLAB Online

You cannot work with two different differential equations for one and the same solution variable (in your case y).

Or is it an implicit equation for p that

d/dt (y'(t)) = y''(t)

or written out

d/dt (sqrt((lambda*f*p*siny/x)+(siny^2/x^2)-(2/lambda^2)+(2*cosy/lambda)-(3*a*p^2*lambda^2/2))) =

(-y'*x'/lambda*x)-(cosy/x)-(f*p'/4)-(f*x'*p/4*x)+(y'*cosy/x)+(siny/lambda)+(lambda*f*p*cosy/4*x)+(siny*cosy/x^2)+(mu_1*(sin(y) - mu_2*cos(y)) / (2 * x^2)

?

Md Sojib less than a minute ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180741

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180741

So, You are suggesting that bvp4c/bvp5c is applicable for only one differential equation with higher order?

Torsten 1 minute ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180761

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180761

Edited: Torsten less than a minute ago

Open in MATLAB Online

No. I say that you can't solve a system of differential equations that contains contradictory equations.

Say you have a system

y'' = 1

y' = 3*t

Then differentiating the last equation gives

y'' = d/dt (3*t) = 3

contradicting the first equation

y'' = 1

Or did you arrive at the equation for y'' by just differentiating y' with respect to t ? Then the equation for y'' is superfluous.

Md Sojib 8 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180776

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180776

Thank you. In that case, is there any alternative way to solve it numerically? I want to give a try. Because I got these equations from derivation.

Actually, I am developing a shape model of a surface by appling calculus of variation method. From that derivation, I got these differential equations which were the common factor of different variational functions.

Torsten 4 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180796

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180796

You didn't answer my questions.

Md Sojib 7 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180821

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180821

Edited: Md Sojib 2 minutes ago

I have already mentioned it my last comment, the equation of y" was not directly came from dy'/dt. lets say, y=y0+eta (y1) ; x=x0+eta (x1) ; p=p0+eta (p1) so on for other functions. I applied these to a specific equation to get minimized shape of that surface. The above equations are the: (differential equation 1) y1 +(differential equation 2)x1 ... so on. I hope I clarify your questions.Please, Let me know If you want to know more on that.

Torsten 2 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180831

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180831

The equations for x and z make no problem because they don't need to be solved. Once you have y, you also have x and z. And expressions for x or z in the equation for y can be substituted by cos(y) and sin(y).

So you need to solve for y and p. What are the equations and what are the boundary/initial conditions ?

Md Sojib 5 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180856

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180856

boundary conditions:

x(0)-R*sin(alpha);

z(0)+R*cos(alpha)/2;

y(0)-alpha;

y'(inf)=0;

p(0)=0;

p'(inf)=0

The equations are mentioned in the code.

Torsten 5 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180861

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180861

Edited: Torsten 5 minutes ago

Open in MATLAB Online

I tried to explain that you cannot use both equations for y because they contradict each other.

And you didn't supply an equation for p. Or - a question you did not yet answer - should p be deduced from the equation

d/dt (y'(t)) = y''(t)

or - written out -

d/dt ( sqrt((lambda*f*p*siny/x)+(siny^2/x^2)-(2/lambda^2)+(2*cosy/lambda)-(3*a*p^2*lambda^2/2)) ) =

(-y'*x'/lambda*x)-(cosy/x)-(f*p'/4)-(f*x'*p/4*x)+(y'*cosy/x)+(siny/lambda)+(lambda*f*p*cosy/4*x)+(siny*cosy/x^2)+(mu_1*(sin(y) - mu_2*cos(y)) / (2 * x^2)

?

Md Sojib 3 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180871

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180871

Edited: Md Sojib 1 minute ago

I don't have any separate equation for p or p'. But after derivation, differential equations contains these two terms.

Torsten 6 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180881

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2125931-need-help-while-defining-ode-function-for-bvp4c-bvp5c-ode45-solve#comment_3180881

Then you will have to dive into the derivation of the equations again. If you don't know the equation for a function within your problem formulation, how do you want to solve it ?

Sign in to comment.

Need help while defining ode function for bvp4c/bvp5c/ode45 solve (2024)
Top Articles
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 5785

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.