sin(x)^2

조회 수: 40 (최근 30일)
Eth
Eth 2019년 4월 8일
댓글: John D'Errico 2022년 11월 22일
How to expand a function like sin(x)^2 to output 1/2*(1-cos(2*x))? I tried expand(sin(x)^2) but it returns the same.

채택된 답변

Star Strider
Star Strider 2019년 4월 8일
Use the rewrite function:
syms x
ys = sin(x)^2;
ye = rewrite(ys, 'exp')
yc = rewrite(expand(ye), 'cos')
p[roducing:
yc =
1/2 - cos(2*x)/2
  댓글 수: 2
Eth
Eth 2019년 4월 8일
Thanks.
Star Strider
Star Strider 2019년 4월 8일
As always, my pleasure.

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

추가 답변 (2개)

Hose Orlando
Hose Orlando 2020년 8월 3일
how do i put this matrix into matlab
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 8월 3일
syms A B C
[sin(A)^2, sin(B)^2, sin(C)^2
cos... etc

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


Carlos Guerrero García
Carlos Guerrero García 2022년 11월 22일
Perhaps the following lines will be useful:
syms x; % Establishing 'x' as a symbolic variable
combine(sin(x)^2,'sincos') % For the 1st (original) question
ans = 
combine(sin(x)^3,'sincos') % For the last question
ans = 
  댓글 수: 1
John D'Errico
John D'Errico 2022년 11월 22일
Note that combine is a useful tool, but one we see mentioned here rarely. So...
help sym/combine
combine Combine terms of the same algebraic structure. combine(S) tries to rewrite products of powers in the expression S as a single power. combine(S, T) combines several calls to the target function T in the expression f to a single call. The target T is specified as one of the strings 'atan', 'exp', 'gamma', 'log', 'sincos', 'sinhcosh'. combine(..., 'IgnoreAnalyticConstraints',VAL) controls the level of mathematical rigor to use on the analytical constraints while combining (branch cuts, division by zero, and so on). Here, VAL can be TRUE or FALSE. If you use TRUE, then combine uses a set of mathematical rules, such as ln(a) + ln(b) = ln(a*b), that are not generally correct, but can give simpler results. The default is FALSE. Examples: combine(2^x * 3^x) returns 6^x combine((2^x)^i) returns (2^x)^i combine((2^x)^i, 'IgnoreAnalyticConstraints', true) returns 2^(x*i) combine(log(x) + log(y), 'log') returns log(x) + log(y) combine(log(x) + log(y), 'log', 'IgnoreAnalyticConstraints', true) returns log(x*y) See also sym/simplify, sym/expand, sym/factor Documentation for sym/combine doc sym/combine

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by