MATLAB: User-defined function as input in “dsolve”

dsolve user-defined functions

Hello everyone, I am new with MATLAB so maybe I can do the following and still haven't figured out how.
I want to use
dsolve ('Dz=a*z+b*t+c(z,t)','t')
where a and/or b are symbolic and
c(z,t) is a user-defined function?
The specific form of the expression is only an example (in principle it could/should be more general. The important thing here is the use of a user-defined function within the expression that defines the differential equation to be solved.
Is there any way I ca do something to this effect?

Best Answer

I think I found the way - it was hidden in an example about using dsolve for a system of ODE that are extracted from a matrix!!
Anyway...
So suppose you have a defined a function r(x,y) (either directly with inline or anonymous function, or extracting from a solution of a previous system, matrix etc)
Then as I understand it you create the string of it
eq=char(r(x,y))
[note if r(x,y) corresponds to a solution ans.w of a previous system then one can define the string eq diectly as eq=char(ans.w)]
and then you use dsolve as follows
dsolve(strcat('Dx=',eq),'t')
[where t is the independent variable (which could be y)]
stracat(s1,s2) is a built-in function that "keeps together" the two strings (in general more than two) 'Dx=' and eq creating a new string that corresponds to the symbolic expression implied by Dx=r(x,y).
It has worked for few examples I played with, but maybe there is a flaw in this I cannot see, or maybe there is a more efficient way of doing it.
Related Question