フィルターのクリア

Solve differential and algebraic equation system

2 ビュー (過去 30 日間)
Surendra Ratnu
Surendra Ratnu 2023 年 9 月 12 日
コメント済み: Torsten 2023 年 9 月 23 日
I tried using the ode15s solver but i am getting this error message 'Index exceeds the number of array elements. Index must not exceed 4.'How can i solve this type of equation system numerically. Here i have 6 variable that depend on the t (in radian). I have equations for 5 variable but not for h_r. h_r is also depend on the t.
Please provide a solution to solve these equations.

採用された回答

Torsten
Torsten 2023 年 9 月 12 日
編集済み: Torsten 2023 年 9 月 12 日
S_1 and q_j are symbolic functions. You have to convert them to numerical functions first (by "MatlabFunction") to use them within ode15s.
After having done this, you could try to determine u_s within the function "ode_vis" by
eq5 = @(u_s)((R-q_j)*u_s*S_1*sin(a)) + ((S_1.^3*sin(a).^3)/(9*u_s))*((1/q_j.^3)-(1/R.^3)) + (R.^ + 2*R*sqrt(pi*s_b)) -((4*S_1*(R-q_j))/(q_j.^2*u_s)) + (16*sin(a)*S_1.^2*(R-q_j).^2/(3*q_j.^3*R*Re)) + ((4*sin(a).^3*S_1.^4*(R-q_j)*(R.^5-q_j.^5))/(15*u_s*q_j.^7*R.^5*Re)) -( (sin(a)*S_1.^2*(R-q_j))/u_s);
u_s = fsolve(eq5,1)
at the beginning of the function instead of setting u_s = y(6).
Or you could add u_s to the solution variables by defining
dydt(6) = ((R-q_j)*u_s*S_1*sin(a)) + ((S_1.^3*sin(a).^3)/(9*u_s))*((1/q_j.^3)-(1/R.^3)) + (R.^ + 2*R*sqrt(pi*s_b)) -((4*S_1*(R-q_j))/(q_j.^2*u_s)) + (16*sin(a)*S_1.^2*(R-q_j).^2/(3*q_j.^3*R*Re)) + ((4*sin(a).^3*S_1.^4*(R-q_j)*(R.^5-q_j.^5))/(15*u_s*q_j.^7*R.^5*Re)) -( (sin(a)*S_1.^2*(R-q_j))/u_s);
and calling ode15s as
M = eye(6);
M(6,6) = 0;
y0=[0.1; 0.3024; 1.5725; 0.10; 0; 0];
[t,y] = ode15s(@(t,y) ode_vis1(t,y,We,Re), tspan, y0,optimset('Mass',M);
  34 件のコメント
Surendra Ratnu
Surendra Ratnu 2023 年 9 月 23 日
yes @Torsten i checked it. Can you tell me there is any other way to solve these equation (means without using odes and somthing like R-K method and etc)??
Torsten
Torsten 2023 年 9 月 23 日
You solved the equations of your model. The solution for your model as it stands explodes at t = 5.88e-2 because you divide by sin(p) which becomes 0. So don't search for new numerical methods because all will give you this solution - search for a modification of your model.

サインインしてコメントする。

その他の回答 (1 件)

William Rose
William Rose 2023 年 9 月 12 日
編集済み: William Rose 2023 年 9 月 12 日
[edit: added several comments]
Your code includes
y0 = [0.1; 0.3024; 1.5725; 0.10];
t = [0 pi];
[t,y] = ode15s(@ode_vis1,t,y0);
I renamed the function from ode_vis to ode_vis1 so that the function name would not conflict with the main file name.
y0 is 4x1, but ode_vis1() returns dydt which is 6x1. y0 and dydt must be the same size.
You can replace line 1 above as shown:
y0=[0.1; 0.3024; 1.5725; 0.10; 0; 0];
This fixes the "Index exceeds number of array elements..." error.
You must replace lines 2 and 3 above with
tspan = [0 pi];
[t,y] = ode15s(@ode_vis1,tspan,y0);
to avoid a conflict involving t.
Since you pass parameters We and Re to ode_vis1(), the call to ode15s() should look like this:
[t,y] = ode15s(@(t,y) ode_vis1(t,y,We,Re), tspan, y0);
The body of function dydt=ode_vis1() includes variables a and m on the right hand side of some equations. Variables a and m are not defined in the function, and they are not passed to the function, and they are not global. You will need to fix this. You can fix it by passing a and m to ode_vis1(), as shown:
function dydt = ode_vis1(t,y, We,Re,m,a)
Then you need to modify the call to ode15s:
[t,y] = ode15s(@(t,y) ode_vis1(t,y,We,Re,m,a), tspan, y0);
There is still an error because ode_vis1() has the variable q on the right hand side, and q is not provided. You need to provide it.
The last element (6th element) of dydt does not appear to be a derivative. You have
dydt = [dudt; dsdt; dpdt; drdt; dhdt; eq5];
The variable eq5 is defined by a logical equality:
eq5 = f(x) == g(x);
where f(x) and g(x) are functions involving many variables. Therefore dydt(6) will be either 1 or 0 each time ode_vis1() is called.
In function dydt=ode_vis1(), you define
u_s = y(6);
Given that definition, then the 6th element of dydt should be the time derivative of u_6. If eq5 is not the derivative of u_6, then you need to fix something.
If eq5 is your attempt to enforce an algebraic equation, then read carefully the Matlab help for differential algebraic equations. Do the example in the help for ode15s involving the Robertson problem. Be sure you understand what a mass matrix is and how to use it. Do the example involving a mass matrix for a baton thrown into the air to gain familiarity with mass matrices.
Good luck with your work.
  2 件のコメント
Surendra Ratnu
Surendra Ratnu 2023 年 9 月 12 日
編集済み: Surendra Ratnu 2023 年 9 月 12 日
u_s is simply algebraic equation. In the first four differential equation, u_s is in equations. u_s is depend on the u_s So 4 differential equation and one algebraic equation want to solve for variable u_b,s_b,p,R,h_r and u_s for the t numerically but i do not know how to deal with that. Here i do not have any equation for h_r. Other than all mention variable, have constant value. So there is any other way to solve these equation numerically ?? if we can defined a difference equation for h_r then solve numerically.
Now i modified the code. Now it did not showing error for q variable. But i do not know how to deal with h_r.
I also tried with DAE solver but wont help for me much.
Please provide me a way to handle this ??
Thank You
William Rose
William Rose 2023 年 9 月 14 日
@Torsten has once again gone above and beyond in his effort to assist.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by