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

조회 수: 83 (최근 30일)
Imran Khan 2024년 5월 26일 13:13
편집: Imran Khan 2024년 5월 27일 12:36
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이전 댓글 6개 표시이전 댓글 6개 숨기기
John D'Errico 2024년 5월 27일 1:35
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 2024년 5월 27일 12:25
편집: Imran Khan 2024년 5월 27일 12:36
@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.

댓글을 달려면 로그인하십시오.

### 채택된 답변

John D'Errico 2024년 5월 26일 16:10
이동: John D'Errico 2024년 5월 27일 1:31
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.

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Steven Lord 2024년 5월 27일 2:31
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?

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by