How do I use ode45 for solving this problem and using the solutions as parameters for solving the next system?
Show older comments
Dear Matlab-community, I got a problem solving some differential-equations-systems.
First I have to say, that I am a beginner in Matlab. I got a system consisting of 6 first order differential equations as a boundary value problem, but I can split them into 3 systems with initial conditions, so I should be able to solve it using ode45. I have to solve the first system and then for solving the second system I need one of the solutions from the first system as a parameter for each x to go on. First I have to solve this system:
(I): Q1’=kappa*Q2 (II): Q2’=-kappa*Q1 (III): -(Q2+dI*kappa)/(E*I)
The (initial)-conditions are: Q1(l)=F1; Q2(l)=F2; Kappa(l)= Ml3/(E*Il), using Il = (B*H^3)/12;
My Matlab code for the function is:
function dy = rigid(x,y)
E = 210000;
I = 3*x; %Funktion für I
dI = 3; %Ableitung dI von I nach dem Weg
dy = zeros(3,1); % a column vector
dy(1) = y(3)*y(2);
dy(2) = -y(3)*y(1);
dy(3) = (-y(2)+dI*y(3))/(E*I);
and my main program:
clc
clear all
%Eingangsparameter:
E = 210000; %N/mm²
Ml3 = 264; %Nmm
F1 = 10; %N
F2 = -15; %N
l = 25; %mm // Länge der Kontur
B = 5; %mm
H = 10; %mm
Il = (B*H^3)/12;
Randbedingung3 = Ml3/(E*Il);
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[X,Y] = ode45(@rigid,[0 l],[F1 F2 Randbedingung3],options);
plot(X,Y(:,1),'-',X,Y(:,2),'-.',X,Y(:,3),'.')
I do not get any values for the solution. I think the problem is that my conditions are not like Q1(0)=…, Q2(0)=…, but at the end of the interval l. I have no idea how to solve this. It would be awesome if someone could pleas help me with this problem and with the following problem:
I need to get the values for y(1), y(2) and y(3) for each x between [0:l]. Then I need to use y(3)(x) which is kappa(x) for solving the next equation:
(i): theta’=kappa with the initial condition theta(x=0)=0 which is easy to solve by getting theta=kappa*x. But therefore I do not know how to get the values for kappa from the solution of the first system for each x.
It would be awesome if someone could please help me out here :-)
17 Comments
Torsten
on 20 Jan 2015
Be careful: Since y3 depends on x, the solution to theta'=kappa is not simply theta=kappa*x.
I suggest you solve the equations simultaneously using bvp4c.
Best wishes
Torsten.
Stefan Henning
on 20 Jan 2015
Torsten
on 20 Jan 2015
1. Don't start at x=0 ; you'll get dy(3)=infinity there.
2. As starting guess, choose y1=F1, y2=F2, y3=Randbedingung3, y4=0, y5=0 and y6=0.
3. Turn your res-vector into a column vector.
Best wishes
Torsten.
Stefan Henning
on 20 Jan 2015
Torsten
on 20 Jan 2015
I guess there is an error in your equations.
Solving only the first three equations, the solutions of all components blow up tremendously. Maybe a problem of units ? Best wishes
Torsten.
Torsten
on 20 Jan 2015
dy(3) and dydx(3) are different in both codes.
I can't decide which formulation is the correct one.
Best wishes
Torsten.
Stefan Henning
on 20 Jan 2015
Torsten
on 20 Jan 2015
I used
and the BVP code works fine for your problem.
I can't explain why the MATLAB error message appears.
Best wishes
Torsten.
Stefan Henning
on 20 Jan 2015
Torsten
on 20 Jan 2015
x=linspace(0.1,l);
y=deval(sol,x);
plot(x,y(1,:),x,y(2,:),x,y(3,:),x,y(4,:),x,y(5,:),x,y(6,:));
Best wishes
Torsten.
Stefan Henning
on 21 Jan 2015
Torsten
on 21 Jan 2015
You mean when you call the deval function ?
It's not necessary to know that yb=l here - the deval function just interpolates the solution from the x-array of the solution saved in the structure "sol" to the points you specify in your vector "x" in the call to deval.
Best wishes
Torsten.
Stefan Henning
on 21 Jan 2015
Torsten
on 21 Jan 2015
You can call the deval-function with sol.x (the mesh selected by bvp4c). Then you can be sure that y(2,end) will be the solution y2 at x=l.
Best wishes
Torsten.
Stefan Henning
on 22 Jan 2015
Torsten
on 22 Jan 2015
Does it not work when you set
y=deval(sol,sol.x);
plot(sol.x,y(1,:),sol.x,y(2,:),sol.x,y(3,:),sol.x,y(4,:),sol.x,y(5,:),sol.x,y(6,:));
?
Best wishes
Torsten.
Stefan Henning
on 22 Jan 2015
Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!