Trigonometric approximation on symbolic variables

Hi,
I would like to know how to perform or represent trigonometric approximations in Matlab. For example, let's say I have the set of symbolic equations
cos(x) + sin(y) = Tp;
1 + x + sin(x) = Tw;
When making the assumption that x and y are small, I want to transform the equations into the form
1 + y = Tp;
1 + x + x = Tw;
Using the subs function to replace all the sines and cosines does not seem to be feasible when I have many variables.
Thank you

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 10 月 6 日
Is it the case that some of the sin() and cos() arguments will be small but others will not? For example in cos(x1x2x3) should it be assumed that x1*x2*x3 will be "small", or is there the possibility that even though x1 and x2 are "small" that when multiplied by x3 that the result might be large enough to count ? Does it all need to be made conditional, something like
piecewise(x < small & y < small & 0 <= small + x & 0 <= small + y, y - Tp + 1, x < small & 0 <= small + x, sin(y) - Tp + 1, y < small & 0 <= small + y, y - Tp + cos(x), cos(x) - Tp + sin(y))
Here -small < x < small was used for the test on x being small enough for the substitution to be valid, with the case where it is not small preserved.
Aik Ann Seng
Aik Ann Seng 2019 年 10 月 6 日
編集済み: Aik Ann Seng 2019 年 10 月 6 日
No need, it can be assumed that all the variables within the sines and cosines are small, so any combination and powers of them can be considered small as well. I'm basically looking for a way to change all sines into their arguments and change all cosines into 1, without having to explicitly state every possible combination of sines and cosines and substituting them.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2019 年 10 月 6 日

0 投票

syms x y Tp Tw
eqn(1) = cos(x) + sin(y) - Tp;
eqn(2) = 1 + x + sin(x) - Tw;
for i = 1:2
eqn(i) = mapSymType( mapSymType(eqn(i), 'sin', @(x)children(x)), 'cos', @(x)1 );
end
This requires R2019a or later.

1 件のコメント

Aik Ann Seng
Aik Ann Seng 2019 年 10 月 6 日
This works perfectly, thank you!

サインインしてコメントする。

その他の回答 (1 件)

darova
darova 2019 年 10 月 5 日

0 投票

subs works ok for me
syms x y Tp Tw
eqn{1} = cos(x) + sin(y) - Tp;
eqn{2} = 1 + x + sin(x) - Tw;
for i = 1:2
eqn{i} = subs(eqn{i},{'sin(y)' 'sin(x)' 'cos(x)'},{y,x,1})
end

1 件のコメント

Aik Ann Seng
Aik Ann Seng 2019 年 10 月 6 日
For this case, subs work due to the simple equations. But my actual model has multiple other variables, and therefore can have many combinations of sines and cosines. Hard substitution for each combination will therefore not be feasible in my case.
For example, if I have 3 variables
syms x1 x2 x3
I will then have the combinations
sin(x1)
sin(x2)
sin(x3)
sin(x1x2)
sin(x1x3)
sin(x2x3)
sin(x1x2x3)
cos(x1)
cos(x2)
cos(x3)
cos(x1x2)
cos(x1x3)
cos(x2x3)
cos(x1x2x3)
And you can see how subs will no longer be practical when I have more and more variables

サインインしてコメントする。

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by