User input not being plugged into the equation

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.

 Accepted Answer

4 Comments

Thank you Walter, I will add tha to my code to generate only the positive answer.
Btw to get back on subject, would you be able to help me with my inquiry above? How can I incorporate a user input command to work with the code above? (refer to the example on the question)
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!