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