ans = 
Converting between x,y cartesian variables to angle in symbolic variables
Show older comments
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 Comments
John D'Errico
on 26 May 2024
What is a Cartesian-like constraint? It seems like you want the toolbox to somehow understand from a line of code, what that code represents to you in terms of a model of some process. I fear that is a big jump to make. It could also be a mistake, where some expression arises from an entirely different system. And I think you do not want the software to be making that sort of a decision in general.
Imran Khan
on 26 May 2024
Can the toolbox understand that I mean x and y are coordinates of a point on a plane, and theta is the angle between them, d is the distance between them, and "understand" that t is the cos of theta? Is there any way to introduce the Cartesian structure to the toolbox?
No. You should think about how to simplify calculation within f to get a simpler output. Of course, you can try to apply "simplify" on the output or substitute expressions in the output by using the "subs" command, but usually it's better to do simplifications beforehand.
Imran Khan
on 26 May 2024
Edited: Imran Khan
on 26 May 2024
Imran Khan
on 26 May 2024
Imran Khan
on 26 May 2024
John D'Errico
on 27 May 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
on 27 May 2024
Edited: Imran Khan
on 27 May 2024
Accepted Answer
More Answers (1)
So instead of the Cartesian coordinate form of those points, you want a polar coordinate form?
syms x y
[th, r] = cart2pol(x, y)
Now you want to work with r and th instead of x and y?
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!