I have an equation like this:
dy/dx = a(x)*y + b
where a(x)
is a non-constant (a=1/x
) and b
is a vector (10000 rows).
How can I solve this equation?
I have an equation like this:
dy/dx = a(x)*y + b
where a(x)
is a non-constant (a=1/x
) and b
is a vector (10000 rows).
How can I solve this equation?
Let me assume you would like to write a generic numerical solver for dy/dx = a(x)*y + b. Then you can pass the function a(x) as an argument to the right-hand side function of one of the ODE solvers. e.g.
a = @(x) 1/x;
xdomain = [1 10];
b = rand(10000,1);
y0 = ones(10000,1);
[x,y] = ode45(@(x,y,a,b)a(x)*y + b,xdomain,y0,[],a,b);
plot(x,y)
Here, I've specified the domain of x
as xdomain
, and the value of y
at the bottom limit of x as y0
.
From my comments, you can solve this without MATLAB. Assuming non-zero x
, you can use an integrating factor to get a 10000-by-1 solution y(x)
y_i(x) = b_i*x*ln(x) + c_i*x
with 10000-by-1 vector of constants c
, where y_i(x)
, b_i
and c_i
are the i
-th entries of y(x)
, b
and c
respectively. The constant vector c
can be determined at some point x0
as
c_i = y_i(x0)/x_0 - b_i*ln(x0)