How to get rid of sign() in diff() results?

8 ビュー (過去 30 日間)
Valeri Aronov
Valeri Aronov 2021 年 6 月 6 日
編集済み: Paul 2021 年 9 月 29 日
I have a symbolic function. diff() produces the result with sign(). The next derivative has dirac() in it. Is there a way to get rid of sign() in the diff() result?

採用された回答

Paul
Paul 2021 年 6 月 6 日
If the goal is to get an expression for the amplitude of the frequency response of H(s) and then differentiate ...
syms R1 R2 C1 C2 w real
assume(R1>=0); assume(R2>=0); assume(C1>=0); assume(C2>=0);
syms s
H(s)=1/(C1*C2*R1*R2*s^2 + (C2*R1 + C2*R2)*s + 1);
A = abs(H(1j*w))
A = 
A = rewrite(A,'sqrt')
A = 
A_R1 = diff(A,R1)
A_R1 = 
A_R1_R1 = diff(A,R1,2)
A_R1_R1 = 
  3 件のコメント
Paul
Paul 2021 年 9 月 29 日
編集済み: Paul 2021 年 9 月 29 日
Running the code here in 2021b yields the following results where it it looks like the rewrite command doesn't accmomplish anything.
syms s
syms C1 C2 C3 R1 R2 R3 w real
ans = 
syms T3(s, C1, C2, C3, R1, R2, R3)
T3(s, C1, C2, C3, R1, R2, R3) = 1/(C1*C2*C3*R1*R2*R3*s^3 + (C1*C3*R1*R2 + C1*C3*R1*R3 + C2*C3*R1*R3 + C2*C3*R2*R3)*s^2 + (C1*R1 + C3*R1 + C3*R2 + C3*R3)*s + 1);
A = abs(T3(1j*w, C1, C2, C3, R1, R2, R3))
A = 
A = rewrite(A, 'sqrt')
A = 
But running the exact code in 2019a yields
which I guess is the result you're looking for.
I'm not sure if the issue is with rewrite, or the fact that the declaration of T3 removes the assumptions on the C* and R* variables, and then rewrite() can't deal with complex variables.
clear all
syms s
syms C1 C2 C3 R1 R2 R3 w real
assumptions
ans = 
syms T3(s, C1, C2, C3, R1, R2, R3)
assumptions
ans = 
In 2019a, the declaration of T3 does not clear the assumptions on C* and R*. I don't know which is the expected behavior.
But I think the code can run the way you want with a simple modification:
clear all
syms s
syms C1 C2 C3 R1 R2 R3 w real
% syms T3(s, C1, C2, C3, R1, R2, R3) this line not needed
T3(s, C1, C2, C3, R1, R2, R3) = 1/(C1*C2*C3*R1*R2*R3*s^3 + (C1*C3*R1*R2 + C1*C3*R1*R3 + C2*C3*R1*R3 + C2*C3*R2*R3)*s^2 + (C1*R1 + C3*R1 + C3*R2 + C3*R3)*s + 1);
A = abs(T3(1j*w, C1, C2, C3, R1, R2, R3));
A = rewrite(A, 'sqrt')
A = 
Valeri Aronov
Valeri Aronov 2021 年 9 月 29 日
Wow, Paul. May I apologize for unaccepting your original answer - it did answer the original question, after all. I thought that this way I will signal the new turn to you and preserve the context.
2021b result looks logical now.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 6 月 6 日
Not sure what you mean because you did not give any examples, but if you want the differences to always be positive, you can pass the results of diff() into abs():
d = abs(diff(v));
  4 件のコメント
Paul
Paul 2021 年 6 月 6 日
I read the post. Sill not clear to me that the intent is to get the derivative of H(s) wrt R1 or if the goal is to get the derivative of abs(H(jw)) wrt R1.
Valeri Aronov
Valeri Aronov 2021 年 6 月 6 日
編集済み: Valeri Aronov 2021 年 6 月 27 日
The purpose is to get the latter - abs(H(jw)) wrt R1.

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

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by