Applying ode45 by giving input by different formula(collocation points)?

조회 수: 2 (최근 30일)
I am trying to olve ode y' = y+1 ( y is a function of x) using ode45 and the x span = [0 1]. But i want to find the value of y at x = (l - 0.5)/2m, where m = 2^j and j = 0,1,2,3,4,.. and l = 1,2,3,4,..

채택된 답변

Fifteen12
Fifteen12 2023년 1월 3일
편집: Fifteen12 2023년 1월 3일
You can read more about specifying specific solution points for ode45 at this link (highlighted). In this case, you want to solve for all the values of x you're wanting to find values of y for, then add those values of x as a parameter for ode45. Something like this gives you the values for y at the specified values of x.
% Find time values (in this case x values)
n = 4;
l = 1:n;
j = 0:n-1;
m = 2.^j;
x = (l - 0.5) ./ (2 * m);
x = sort(x);
% Make dummy y function
y_prime = @(x) 1/3 * x^3;
y0 = 0;
% Run ODE45
[x, y] = ode45(@(x, y) y_prime(x), x, y0);
Note that I had to make some assumptions for this to work: I had to sort x to make it always increasing, and I assumed what you wanted y(x) to be, as well as your initial conditions for it.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by