Unable to isolate variable from expression using 'solve'.

조회 수: 9 (최근 30일)
Hello, I am trying to reproduce all steps to create a transfer function from the beginning.
As seen on the code bellow, I managed to get to the equation F(s), then I isolated Xo using solve.
syms xi(t) xo(t) t B M K s Xo Xi;
xo2 = diff(xo(t),2);
xo1 = diff(xo(t),1);
xi2 = diff(xi(t),2);
xi1 = diff(xi(t),1);
f = xo2 + (B/M)*xo1 + (K/M)*xo -((B/M)*xi1 + (K/M)*xi);
F = laplace(f,t,s);
F = subs(F,{'xo(0)','D(xo)(0)','xi(0)','laplace(xo(t),t,s)','laplace(xi(t),t,s)'},{0,0,0,Xo,Xi})==0;
FXo = solve(F,Xo)==Xo;
pretty(FXo)
Which results in:
K Xi + B Xi s
-------------- == Xo
2
M s + B s + K
In order to create a transfer function I need Xo/Xi , so I used solve again, but this time I used:
solve(FXo,Xo/Xi)
This code results in:
ans =
Xi: [0x1 sym]
s: [0x1 sym]
Then I modified the 2 last lines of the code to:
FXo = solve(F,Xo)==1
pretty(FXo)
solve(FXo,1/Xi)
But it resulted the same. I also tried to use only one solve with Xo/Xi as parameter but it didn't work. Thanks in advance!
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 6월 19일
In your
f = xo2 + (B/M)*xo1 + (K/M)*xo -((B/M)*xi1 + (K/M)*xi);
it is better to use
f = xo2 + (B/M)*xo1 + (K/M)*xo(t) -((B/M)*xi1 + (K/M)*xi(t));
Saves problems when trying to cross-verify with other packages.
Pedro Ricardo Garcia de Oliveira
Thank you, I will correct it asap.

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

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 19일
You appear to be attempting to solve for an expression Xo/Xi instead of solving for a variable. When you using the symbolic toolbox solve() function, then any expressions you give that are not pure variables are taken as expressions that must be solved for equality with 0.
In order to get Xo/Xi what you should be doing is dividing both sides of FXo by Xi. Just divide, not solve().
  댓글 수: 1
Pedro Ricardo Garcia de Oliveira
That makes a lot of sense, thank you. I ended up using this code:
FXo = solve(F,Xo);
FXo=FXo^-1==1;
FXo = solve(FXo,Xi);
Fs = Xo/Xi==FXo^-1;
It's not pretty, and probably not the recommended way of doing it, but it is working so far. When I finish this I will come back to this part of the code and I will use division. I thought solve would work for expressions, not only variables... I'm a bit disappointed actually xd.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by