필터 지우기
필터 지우기

Solving Differential Equation with initial conditions

조회 수: 3 (최근 30일)
onsagerian
onsagerian 2018년 2월 10일
댓글: Star Strider 2018년 2월 11일
Hello,
I tried to make a simple code for solving a coupled differential equation with initial conditions, but I got the following errors.(two separate errors) Would you check my code with the error message and make a correction?
syms S_1(t) S_2(t);
K=1;
k_1=20;
k_2=5;
k_3=5;
k_4=5;
k_5=2;
n=4;
S_1(0)=0.0;
S_2(0)=0.6;
dsolve(diff(S_1,t)==k_1*S_2^n/(K^n+S_2^n)-k_3*S_1-k_5*S_1)
dsolve(diff(S_2,t)==k_2+k_5*S_1-k_4*S_2)
Error using sym/subsasgn (line 942)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in cal_test11 (line 10)
S_1(0)=0.0;

채택된 답변

Star Strider
Star Strider 2018년 2월 10일
You need to add the initial conditions as arguments to dsolve, and use the ‘double equal’ to assign them:
S_1s = dsolve(diff(S_1,t)==k_1*S_2^n/(K^n+S_2^n)-k_3*S_1-k_5*S_1, S_1(0)==0.0)
S_2s = dsolve(diff(S_2,t)==k_2+k_5*S_1-k_4*S_2, S_2(0)==0.6)
  댓글 수: 5
onsagerian
onsagerian 2018년 2월 11일
Thank you all for your explanation. I will see the documents.
Star Strider
Star Strider 2018년 2월 11일
My pleasure.
Those links completely describe the code needed to convert your symbolic ODEs to anonymous functions.
Do not include the initial conditions ‘S_1(0)’ and ‘S_2(0)’ in the code you send to odeToVectorField. You will set the initial conditions as arguments to the ODE solver you choose.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by