User input not being plugged into the equation

조회 수: 8 (최근 30일)
Thamer
Thamer 2013년 8월 6일
Hello,
Something tells me there's a simple solution to my problem, but i can't seem to figure it out. Here's my code:
prompt={'Enter value for R_bd: ', 'Enter value for R_ad: ', 'Enter value for R_ae: ', 'Enter value for R_be: '};
answer=inputdlg(prompt);
x1 = str2num(answer{1});
x2 = str2num(answer{2});
x3 = str2num(answer{3});
x4 = str2num(answer{4});
equ1='x1-R1*(R2+R3+R4)/(R1+R2+R3+R4)';
equ2='x2-R2*(R1+R3+R4)/(R1+R2+R3+R4)';
equ3='x3-R3*(R1+R2+R4)/(R1+R2+R3+R4)';
equ4='x4-R4*(R1+R2+R3)/(R1+R2+R3+R4)';
sol=solve(equ1,equ2,equ3,equ4);
R1=sol.R1
R2=sol.R2
R3=sol.R3
R4=sol.R4
My issue with this code is, the number being entered by the user (say you input 3 for all the four answers) is not being plugged in equ1 - equ4 to generate an answer.
When I write the code like this it works just fine:
equ1='3-R1*(R2+R3+R4)/(R1+R2+R3+R4)';
equ2='3-R2*(R1+R3+R4)/(R1+R2+R3+R4)';
equ3='3-R3*(R1+R2+R4)/(R1+R2+R3+R4)';
equ4='3-R4*(R1+R2+R3)/(R1+R2+R3+R4)';
sol=solve(equ1,equ2,equ3,equ4)
R1=sol.R1
R2=sol.R2
R3=sol.R3
R4=sol.R4
But the values can vary which is why I need the user to input the values. What am I doing wrong?
Thank you in advance.

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 6일
  댓글 수: 4
Walter Roberson
Walter Roberson 2013년 8월 6일
prompt={'Enter value for R_bd: ', 'Enter value for R_ad: ', 'Enter value for R_ae: ', 'Enter value for R_be: '};
answer=inputdlg(prompt);
x1 = str2num(answer{1});
x2 = str2num(answer{2});
x3 = str2num(answer{3});
x4 = str2num(answer{4});
syms R1 R2 R3 R4 positive
equ1=x1-R1*(R2+R3+R4)/(R1+R2+R3+R4);
equ2=x2-R2*(R1+R3+R4)/(R1+R2+R3+R4);
equ3=x3-R3*(R1+R2+R4)/(R1+R2+R3+R4);
equ4=x4-R4*(R1+R2+R3)/(R1+R2+R3+R4);
sol=solve(equ1,equ2,equ3,equ4);
R1=sol.R1
R2=sol.R2
R3=sol.R3
R4=sol.R4
Thamer
Thamer 2013년 8월 7일
Thanks!

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by