Calculate a letter from equation with letters.
Show older comments
Hello.
I am just wondering that how I can calculate a letter from the equation with letters. For example here,
if I want to get cos1 and sin1 from these equation, how do I need to type the function??
syms Xe Ye a1 a2 cos1 cos2 sin1 sin2
Xe = a2*(cos1*cos2-sin1*sin2)+a1*cos1;
Ye = a2*(sin1*cos2)+a1*sin1;
Thank you in advance.
Accepted Answer
More Answers (2)
Walter Roberson
on 15 Jun 2020
syms Xe Ye a1 a2 cos1 cos2 sin1 sin2
Xe = a2*(cos1*cos2-sin1*sin2)+a1*cos1;
Ye = a2*(sin1*cos2)+a1*sin1;
sol = solve([Xe,Ye],[sin1,cos1])
sol =
struct with fields:
sin1: [1×1 sym]
cos1: [1×1 sym]
>> sol.sin1
ans =
0
>> sol.cos1
ans =
0
You might want to do this:
syms Xe Ye a1 a2 cos1 cos2 sin1 sin2
eq(1) = Xe == a2*(cos1*cos2-sin1*sin2)+a1*cos1;
eq(2) = Ye == a2*(sin1*cos2)+a1*sin1;
sin1_sol = isolate(eq(2),sin1);
cos1_sol = isolate(eq(1),cos1);
cos1_sol = subs(cos1_sol,sin1,rhs(sin1_sol));
pretty(sin1_sol)
pretty(cos1_sol)
results in:
Ye
sin1 == ------------
a1 + a2 cos2
Ye a2 sin2
Xe + ------------
a1 + a2 cos2
cos1 == -----------------
a1 + a2 cos2
Categories
Find more on Symbolic Math Toolbox 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!