How do I solve an ODE of the form y'=ay^3 +by^2 +cy +d?

조회 수: 2 (최근 30일)
Gabriel Baranoski
Gabriel Baranoski 2022년 1월 25일
댓글: Jon 2022년 1월 26일
I have a vector, for example "pn" of size (20,1). Each point of data describes a coeffecient of y to the power of 20 minus that data point indices (made from the polyfit function in matlab).
For example, pn(15,1) = 5 translates to 5y^5
This defines a large polynomial which looks similar to the title example.
I know that the ODE I have is of the form y'=ay^19 + by^18 +cy^17 +...+gy +h
how can i solve this ode to make a plot of y as a function of t?
I know about the ODE functions like ode45 etc, but I'm not sure how to use them with my ode form.
Thanks!
  댓글 수: 1
James Tursa
James Tursa 2022년 1월 25일
편집: James Tursa 2022년 1월 25일
Can you verify that the form has y's in the polynomial and not x's or t's? And do you have numeric initial conditions?

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

채택된 답변

Jon
Jon 2022년 1월 25일
The ode solvers, e.g. ode45 require a function handle which will evaluate the current value of the derivative given the current state. So define your function for example as:
fun = @(y)polyval(pn,y)

추가 답변 (1개)

Gabriel Baranoski
Gabriel Baranoski 2022년 1월 26일
Hey so I ended up figuring it out. This is my code to solve the ODE below:
FK=polyfit(MFPs(:,1),MFPs(:,2),20);
tspan = [0 :0.05:50];
x0 = 0;
[t,v]=ode45(@(t,v) ((FK(1)*v^20) + (FK(2)*v^19) + (FK(3)*v^18) + (FK(4)*v^17) + (FK(5)*v^16) + (FK(6)*v^15) + (FK(7)*v^14) + (FK(8)*v^13) + (FK(9)*v^12) + (FK(10)*v^11) + (FK(11)*v^10) + (FK(12)*v^9) + (FK(13)*v^8) + (FK(14)*v^7) + (FK(15)*v^6) + (FK(16)*v^5) + (FK(17)*v^4) + (FK(18)*v^3) + (FK(19)*v^2) + (FK(20)*v) + (FK(21)) - FR - (Y*(v^2)))/M ,tspan,x0);
plot (app.UIAxes,t,v*3.6);
There are a few terms included there that change the ODE from how i originally stated, but this solves the ode accurately.
Maybe theres a way to reduce the ode solve command but I'm not to sure how.
  댓글 수: 4
Gabriel Baranoski
Gabriel Baranoski 2022년 1월 26일
oh okay, great thanks!
Jon
Jon 2022년 1월 26일
Great, glad you got it working. Good luck with your project

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

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by