I have created a function in which I am solving a partial differential equation where temperature is dependent on time and radius (energy balance in spherical coordinates). I have discretised the spatial coordinates into n nodes. This yielded an ode with respect to time that I must complete over each node. There are also two other differential equations (not relevant to this however, its solutions are stored in n+1 and n+2 of the DyDt matrix just for information). I have shown the relevant parts of the code for brevity:
T = zeros(n,1); %initialise T as a matrix
DTDt = zeros(n,1); %initialise DTdt as a matrix
DyDt = zeros(n+2,1); %initialise a matrix containing DTdt from 1:n. (the n+1 and n+2 are the two other solutions)
T = y(1:n); %fill the T values into a y matrix from 1 to nth column
I then have a for loop for i=1:n-1 with my expression for DTDt. This allows me to solve all nodes up unti n-1. However, my problem is for the solution to T(n), I do not have a DTdt equation, but instead I have an algebraic equation:
It relies only only values from the other nodal positions and some other constants.
In a separate file, I utilise the functions, setting the initial condition as T0 at 298K.
How can I go about solving such a system? I understand it is a set of differential equations and 1 algebraic equation.
Thank you very much in advance. I am a beginner in Matlab and will appreciate any help.