how to express operators in symbolic algebra

I want to express an operator, P, which is simply the differential operator. I cannot find how to do this--one failed attempt is shown--any help appreciated
Fritz
==============================================
clear all
syms x
syms P(q), q(x)
q(x)=x^2
P(q) = diff(q(x),1) +5
return

Risposte (3)

MATLAB does not support creating operators: it only supports creating functions and expressions.
For example, P^3 to represent third derivative is not supported by MATLAB.
Torsten
Torsten il 17 Dic 2023
Modificato: Torsten il 17 Dic 2023
Maybe like this
syms x
syms P(x) q(x)
q(x) = x^2
P(x) = diff(q(x),1) + 5
?
You can't define P as a function of a dependent variable (q).
You could define PP(x) = P(q(x)), if you want.

1 Commento

Fritz Sonnichsen
Fritz Sonnichsen il 17 Dic 2023
Spostato: Dyuman Joshi il 21 Dic 2023
P(q(x)) = diff(q(x),1) dosen't seem to work either. Maybe the simpler way to answer this question is:
How to I express and operator in matlab symbolic algebra? (The operator can be any assortment of things but in my case generally a differential plus a constant.
thanks
Fritz

Accedi per commentare.

Paul
Paul il 17 Dic 2023
Modificato: Paul il 17 Dic 2023
I'm not sure how define a function of a function. But this seems to work, at least for this simple case:
syms x t
syms q(t) v(x) % v is our dummy function
P = diff(v,argnames(v),1) + 5 % "operator" P
P(x) = 
q(t) = t^2
q(t) = 
P(t) % show what P(t) is
ans = 
subs(P(argnames(q)),v,q) % subs the dummy function with the actual function
ans = 
Or, more generally w/o needing to know the symfun buried in P
subs(P(argnames(q)),symfun(findSymType(P,'symfun'),symvar(P)),q) % subs the dummy function
ans = 
I'm not sure this is the best way.
It can probably be wrapped in cleaner functionality, like
operateon = @(P,q) subs(P(argnames(q)),symfun(findSymType(P,'symfun'),symvar(P)),q); % subs the dummy function
operateon(P,q)
ans = 
Exending to other operations as defined in Matlab
operateon(2*P,q)
ans = 
operateon(P^3,q)
ans = 

6 Commenti

Fritz Sonnichsen
Fritz Sonnichsen il 21 Dic 2023
Spostato: Dyuman Joshi il 22 Dic 2023
OK-your attention to this is appreciated
-I am still working on the best way to do this but I think the comment here indicates that matlab-sym does not have a way to directly do operator algebras--I must use a function.
Of additional interest here---I note you are able to get graphic values (instead of messy text values) for your results. I was looking for an option to do this and cannot find one. Can you tell me how to turn this on?
thanks
Fritz
Paul
Paul il 21 Dic 2023
Spostato: Dyuman Joshi il 22 Dic 2023
Use Live Script to see Symbolic Toolbox Results with mathematical formatting.
Here on Answers, the formatting is done automatically when running code with the Run button.
Fritz Sonnichsen
Fritz Sonnichsen il 22 Dic 2023
Spostato: Dyuman Joshi il 22 Dic 2023
OK--I never would have guessed! Live Script is now working and makes things a lot easier to read as my equations accumulate a lot of clutter
thanks
fritz
Paul
Paul il 22 Dic 2023
Spostato: Dyuman Joshi il 22 Dic 2023
If you need to export your symbolic equations out of Matlab to some other application, you may also be interested in: latex.
p.s. In the future, please be careful about creating a new answer that really should be a comment to an existing answer. I've made that mistake myself because the new answer box is just below and much bigger than the comment box for preceding answer.
Fritz Sonnichsen
Fritz Sonnichsen il 22 Dic 2023
Spostato: Dyuman Joshi il 22 Dic 2023
thanks for the comment - I think I have this answer in the correct box now. -I used latex many years ago and probably should review it. Fritz
I've moved the responses to be continued under @Paul's answer.
Also, @Fritz Sonnichsen, if this answer solved your problem, please consider accepting the answer. The general idea is to accept the answer that is most fitting to the question asked.
Accepting an answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.
You can accept only 1 answer for a question, but you can vote for as many answers as you want. Voting an answer also provides reputation points.

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Tag

Richiesto:

il 17 Dic 2023

Commentato:

il 22 Dic 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by