Solve function with variables

조회 수: 5 (최근 30일)
Emrecan
Emrecan 2012년 8월 7일
syms c ho
S=solve('c^2/(2*R)+(2*delta_p*c*(pi-2))/(pi*Er)+ho-h_lk=0','w(i)=ho+(2*c*delta_p)/Er');
I am trying to solve variables in the equation, only c and ho are the unknown variables. w(i) is changing in the loop, and I want to calculate variable values continuously. Other varibles are the known and assigned values. How can I solve the problem? solve function currently wants everything numerical except the unknowns.
Thanks
Emrecan
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 7일
what are the unknown variables?
Emrecan
Emrecan 2012년 8월 8일
c and ho are the unknown variables

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

답변 (3개)

Matt Fig
Matt Fig 2012년 8월 7일
편집: Matt Fig 2012년 8월 8일
You can specify the variables of interest to the solve command.
S=solve('c^2/(2*R)+(2*delta_p*c*(pi-2))/(pi*Er)+ho-h_lk=0','w(i)=ho+(2*c*delta_p)/Er','c','ho');
To replace the indexed w, use:
S=solve('c^2/(2*R)+(2*delta_p*c*(pi-2))/(pi*Er)+ho-h_lk=0',sprintf('%f=ho+(2*c*delta_p)/Er',w(ii)),'c','ho');

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 7일
s1='c^2/(2*R)+(2*delta_p*c*(pi-2))/(pi*Er)+ho-h_lk=0',
s2=[num2str(w(i)) '=ho+(2*c*delta_p)/Er']);
s=solve(s1,s2,'c','ho')
  댓글 수: 2
Emrecan
Emrecan 2012년 8월 8일
I need something like num2str, but in this case it does not work.
Matt Fig
Matt Fig 2012년 8월 8일
What does that mean, "It doesn't work"? Did you get an error? If so, what error? Did MATLAB crash? Did the computer catch fire? Please be more specific. Also, you might try SPRINTF as I show above.

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


Walter Roberson
Walter Roberson 2012년 8월 8일
syms c ho
S = solve(c^2/(2*R)+(2*delta_p*c*(pi-2))/(pi*Er)+ho-h_lk, ho+(2*c*delta_p)/Er - w(i), c, ho);

Community Treasure Hunt

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

Start Hunting!

Translated by