How can i convert symbolic sin function to cos

44 ビュー (過去 30 日間)
Tobias Kristensen
Tobias Kristensen 2022 年 9 月 16 日
回答済み: Apeksha Bagrecha 2022 年 9 月 21 日
Hello
After looking through mathworks for answer, i found nothing that seemed helpfull. In 3 phase AC theory you nearly always want the AC waves written as a function of cos, i made a function that converts between reference frames, but in some cases it writes the symbolic function as sin and not as cos. I have tried to use collect, rewrite and simplify, but the way i used them it didnt work.
2 outputs of the function im not happy about:
[DOut_Valuesabc] = f_RefFrame(f,"SR","abc")
[DOut_Values_AB_to_SR] = f_RefFrame(DOut_Values_abc_to_AB,"AB","SR")
First one is obvious, it should be cos not sin, second one i want rewritten i as an exponential, but it also dont want to do that. Have for example tried this:
simplify(rewrite(expand(rewrite(DOut_Valuesabc, 'exp')), 'cos'))
and:
simplify(rewrite(DOut_Valuesabc,'cos'),'steps',50)
Again it does not work.
I tried to include as much as possible so any eventual helpers do not need to open my files, which could easily become very confusing.
Any feedback in asking the question is welcome since it is my first question
  1 件のコメント
Sam Chak
Sam Chak 2022 年 9 月 16 日
編集済み: Sam Chak 2022 年 9 月 16 日
Not exactly sure how to do it. Unsuccessful in some cases. Need to re-read documentation.
Update: 'sin' or 'cos' will perform the same thing as rewrite(y, 'sincos').
syms x
y1 = sin(x + pi/2);
sin2cos = simplify(rewrite(expand(rewrite(y1, 'tan')), 'cos'))
sin2cos = 
y2 = sin(x - pi/2);
sin2cos = simplify(rewrite(expand(rewrite(y2, 'tan')), 'cos'))
sin2cos = 
y3 = sin(x - pi/4);
sin2cos = simplify(rewrite(expand(rewrite(y3, 'tanh')), 'cos'))
sin2cos = 
help rewrite
REWRITE Rewrite symbolic expressions S in terms of target T. REWRITE(S,T) rewrites the symbolic expression S in terms of the target T. The target T is specified as one of the strings 'exp', 'log', 'sincos', 'sin', 'cos', 'tan', 'cot', 'sinhcosh', 'sinh', 'cosh', 'tanh', 'coth', 'asin', 'acos', 'atan', 'acot', 'asinh', 'acosh', 'atanh', 'acoth', 'sqrt', 'heaviside', 'piecewise'. The target T may also be a symbolic unit or a vector of symbolic units. REWRITE(S, T) with a symbolic unit S rewrites all symbolic units in S in terms of the symbolic unit T. The target T may also by a vector of symbolic units. In this case, the units in S are rewritten involving some, but not necessarily all, entries of T. If T is '1', the function tries to convert a dimensionless unit into its numeric value. T may also be name (string or character vector) of a unit system such as 'SI', 'CGS' etc. In this case, the units in S are rewritten in terms of the base units of the given unit system. REWRITE(S, T, 'Temperature', 'difference') treats all temperature units in S as units of temperature differences. REWRITE(S, T, 'Temperature', 'absolute') treats all temperature units in S as units of absolute temperatures. In this case, S must be a product of a dimensionless symbolic object (such as a symbolic number or a variable) and a symbolic temperature unit. REWRITE(S,'exp') rewrites all trigonometric and hyperbolic functions in terms of EXP. Furthermore, the inverse functions are rewritten in terms of LOG. REWRITE(S,'log') rewrites the functions ASIN, ACOS, ATAN, ACOT, ASINH, ACOSH, ATANH, ACOTH, ARG in terms of LOG. REWRITE(S,'sincos') rewrites the functions TAN, COT, EXP, SINH, COSH, TANH and COTH in terms of SIN and COS. REWRITE(S,'sin') does the same as REWRITE(S,'sincos'). In addition to that, cos(x)^2 is rewritten as 1-sin(x)^2. REWRITE(S,'cos') does the same as REWRITE(S,'sincos'). In addition to that, sin(x)^2 is rewritten as 1-cos(x)^2. REWRITE(S,'tan') rewrites the functions SIN, COS, COT, EXP, SINH, COSH, TANH, COTH in terms of TAN. REWRITE(S,'cot') rewrites the functions SIN, COS, EXP, SINH, COSH, TANH, COTH in terms of COT. REWRITE(S,'sinhcosh') rewrites the functions EXP, TANH, COTH, SIN, COS, TAN and COT in terms of SINH and COSH. REWRITE(S,'sinh') does the same as REWRITE(S,'sinhcosh'). In addition to that, cosh(x)^2 is rewritten as sinh(x)^2 + 1. REWRITE(S,'cosh') does the same as REWRITE(S,'sinhcosh'). In addition to that, sinh(x)^2 is rewritten as cosh(x)^2 - 1. REWRITE(S,'tanh') rewrites the functions SIN, COS, COT, EXP, SINH, COSH, COTH in terms of TANH. REWRITE(S,'coth') rewrites the functions SIN, COS, COT, EXP, SINH, COSH, TANH in terms of COTH. REWRITE(S,'asin') rewrites the functions LOG, ACOS, ATAN, ACOT, ASINH, ACOSH, ATANH, ACOTH in terms of ASIN. REWRITE(S,'acos') rewrites the functions LOG, ASIN, ATAN, ACOT, ASINH, ACOSH, ATANH, ACOTH in terms of ACOS. REWRITE(S,'atan') rewrites the functions LOG, ASIN, ACOS, ACOT, ASINH, ACOSH, ATANH, ACOTH in terms of ATAN. REWRITE(S,'acot') rewrites the functions LOG, ASIN, ACOS, ATAN, ASINH, ACOSH, ATANH, ACOTH in terms of ACOT. REWRITE(S,'asinh') rewrites the functions LOG, ASIN, ACOS, ATAN, ACOT, ACOSH, ATANH, ACOTH in terms of ASINH. REWRITE(S,'acosh') rewrites the functions LOG, ASIN, ACOS, ATAN, ACOT, ASINH, ATANH, ACOTH in terms of ACOSH. REWRITE(S,'atanh') rewrites the functions LOG, ASIN, ACOS, ATAN, ACOT, ASINH, ACOSH, ACOTH in terms of ATANH. REWRITE(S,'acoth') rewrites the functions LOG, ASIN, ACOS, ATAN, ACOT, ASINH, ACOSH, ATANH in terms of ACOTH. REWRITE(S,'sqrt') rewrites complex absolute values abs(x+i*y) as sqrt(x^2 + y^2) if x and y are real symbolic expressions. REWRITE(S,'heaviside') rewrites the function SIGN in terms of HEAVISIDE. REWRITE(S,'piecewise') rewrites the functions ABS, SIGN, and HEAVISIDE in terms of PIECEWISE. Examples: u = symunit; rewrite(1.234*u.cm, u.inch) returns (617/1270)*[in] rewrite(u.Newtonmeter, [u.Newton,u.inch]) returns (5000/127)*[N]*[in] rewrite({0, u.Kelvin}, u.Celsius, 'Temperature', 'absolute') returns -(5463/20)*[Celsius] syms x; rewrite(sin(x),'exp') returns (exp(-x*1i)*1i)/2 - (exp(x*1i)*1i)/2 rewrite((exp(-x*1i)*1i)/2 - (exp(x*1i)*1i)/2,'sincos') returns sin(x) rewrite(asinh(x),'log') returns log(x + (x^2 + 1)^(1/2)) rewrite((1/exp(x*i))*(1/2+i/2)+exp(x*i)*(1/2+(-i/2)), 'sincos') returns cos(x) + sin(x) rewrite(tan(x),'sin') returns -sin(x)/(2*sin(x/2)^2 - 1) rewrite(tan(x),'sincos') returns sin(x)/cos(x) rewrite(sym('sign(x)'),'heaviside') returns 2*heaviside(x) - 1 syms x y real; rewrite(abs(x+1i*y),'sqrt') returns (x^2 + y^2)^(1/2) See also SYMUNIT, SYM/SIMPLIFY, SYM/FACTOR, SYM/COLLECT, SYM/SIMPLIFYFRACTION. Documentation for rewrite doc rewrite

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

回答 (1 件)

Apeksha Bagrecha
Apeksha Bagrecha 2022 年 9 月 21 日

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by