Quick Question - Clean up code

조회 수: 4 (최근 30일)
Steve
Steve 2012년 3월 25일
Hi - thanks for your time.
I have the following code:
PO = 0.15;
syms s
Dratio = solve ('0.15=exp(-(pi*s)/(sqrt(1-(s^2))))','s')
However, I'd like the '0.15' in the Dratio equation to be PO but when I do this - matlab returns the value as a long ugly expression of logs instead of 0.51.
Also when the code is used as it currently is (with 0.15 instead of PO) matlab returns a negative answer and a positive one. Is there a way to ignore the negative answer?

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 3월 25일
PO = 0.15;
syms s
Dratio = double(solve(exp(-pi*s/sqrt(1-s^2))-PO));
Dratio(Dratio > 0)
  댓글 수: 3
Alexander
Alexander 2012년 3월 26일
You can also declare |s| to be positive:
PO = 0.15;
syms s positive
Dratio = double(solve(exp(-pi*s/sqrt(1-s^2))-PO))
Dratio =
0.5169
Oleg Komarov
Oleg Komarov 2012년 3월 26일
That's clever! I tried to play around with assume(s > 0) but it didn't work for some reason, didn't know you could use positive.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by