Introducing a Variable in simple equation?

조회 수: 5 (최근 30일)
Mahbubur Rahman
Mahbubur Rahman 2016년 2월 11일
댓글: Walter Roberson 2016년 2월 11일
Why is simple code is not working? I am a novice here.
Qc = 40;
Qr = 55;
I = 78;
Qs = 100;
I = sqrt((Qc + Qr -Qs)/R_Ts);
disp(R_Ts)
It is showing Undefined function or variable 'R_Ts'.

답변 (1개)

John D'Errico
John D'Errico 2016년 2월 11일
편집: John D'Errico 2016년 2월 11일
You have not defined that variable. How does MATLAB know what it is? You defined all the other variables, but not that one.
If you have the symbolic toolbox, then do this first:
syms R_Ts
Now, it appears as if you want MATLAB to know that you wish to solve for the unknown variable. Computer programs don't read your mind. They do what you tell them to do.
Qc = 40;
Qr = 55;
I = 78;
Qs = 100;
This next line creates an equation of the equality as you posed it, with the unknown variable R_Ts in it.
EQ = I == sqrt((Qc + Qr -Qs)/R_Ts);
And now we apply solve.
R_Ts = solve(EQ,R_Ts)
-5/6084
Or, convert that to a numeric form:
vpa(R_Ts)
ans =
-0.00082182774490466798159105851413544
double(R_Ts)
ans =
-0.000821827744904668
  댓글 수: 2
Mahbubur Rahman
Mahbubur Rahman 2016년 2월 11일
편집: Walter Roberson 2016년 2월 11일
Thanks a lot for the reply. But what if there are two equations containing the R_Ts, like this -
Qr = 55;
I = 78;
Qs = 100;
Qc = 45*I - ((R_Ts)^2);
I = sqrt((Qc + Qr -Qs)/R_Ts);
disp(R_Ts)
What to do this stage? And why the disp does not work in these cases?
Walter Roberson
Walter Roberson 2016년 2월 11일
You would still need the
syms R_Ts
before you use R_Ts, and you still need the solve(),
syms R_Ts
Qr = 55;
I = 78;
Qs = 100;
Qc = 45*I - ((R_Ts)^2);
Eq = I == sqrt((Qc + Qr -Qs)/R_Ts)
R_Ts = solve(EQ,R_Ts)
sol =

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by