User input not being plugged into the equation

3 visualizaciones (últimos 30 días)
Thamer
Thamer el 6 de Ag. de 2013
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Ag. de 2013
  4 comentarios
Walter Roberson
Walter Roberson el 6 de Ag. de 2013
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 el 7 de Ag. de 2013
Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by