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,..
1 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!