Converting between x,y cartesian variables to angle in symbolic variables

5 Ansichten (letzte 30 Tage)
Is there some way to write "Cartesian"-like constraints around symbolic variables? For example, is there any way to tell the toolbox that it should interpret x and y as Cartesian in the following code:
clear all;clc;close all
syms x y real
t=x/sqrt(x^2 + y^2);
And write "t" to be the cos of an angle between the (x,y) vector and the x-axis?
  8 Kommentare
John D'Errico
John D'Errico am 27 Mai 2024
I suppose one day, maybe sooner than I really expect to see, AI tools will be smart enough to do as you want. I'm not sure that would make me happy, but then, I grew up using a slide rule, using pencil and paper to do my work.
Imran Khan
Imran Khan am 27 Mai 2024
Bearbeitet: Imran Khan am 27 Mai 2024
@John D'Errico, I'm not sure if this might require an AI approach. Perhaps I'm missing something further, but I think it may only require the addition of user-defined relations between the variables with the intermediate variables r,phi - your above code snippet is nearly there. Symmath already has simplify (and "IgnoreAnalyticConstraints" tells me that it does keep some identities "in mind" when simplifying, and decides when to use them too), and it already uses some default identities in rewrite too. There just needs to be a way to say "here, keep these user-defined relations in mind too and play around with them in simplifying". So adding such a feature that initializes the problem should be alright - it needs to figure out when to stop. Maybe an AI tool would be useful in that.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 26 Mai 2024
Verschoben: John D'Errico am 27 Mai 2024
No, the toolbox will never try to understand your equations, and then infer what the variables mean to you, and then perform substitutions that you think right.
A problem is that even though you think of x and y as living in a cartesian coordinate system, to syms, it just sees variables. There is no understanding there, at least not yet. Maybe in the future. And certainly, it cannot automatically perform transformations like that.
In SOME circumstances, you can get rewrite to simplify some expressions, but that often just takes just trial and error in my experience. Or you can use simplify to give you many different alternate simplifications, then picking the one you like.
Of course, if you want it to make the transformations you are discussing here, you can do things like this:
syms x y
t=x/sqrt(x^2 + y^2);
syms theta
syms r real positive
simplify(subs(t,[x,y],[r*cos(theta),r*sin(theta)]))
ans = 
But here I have explicitly told it to do the transformations you seem to want.
Getting symbolic algebra tools to do as you wish can sometimes be a skill, sometimes an art, and sometimes a bit of magic is need to get the result you wish to see.

Weitere Antworten (1)

Steven Lord
Steven Lord am 27 Mai 2024
So instead of the Cartesian coordinate form of those points, you want a polar coordinate form?
syms x y
[th, r] = cart2pol(x, y)
th = 
r = 
Now you want to work with r and th instead of x and y?

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by