Solving an equation of 3 unknown variables by inputing 3 sets of data

조회 수: 8 (최근 30일)
Dimitris Gkoutzamanis
Dimitris Gkoutzamanis 2021년 11월 24일
답변: Dimitris Gkoutzamanis 2021년 11월 24일
Hello everyone,
I am a rookie in Matlab. This is my first routine.
I would like to solve a three variable equation (A, B, C) by inputing 3 sets of data (x1,y1 | x2,y2 | x3,y3).
The equation is y=A+Bx+C/x.
I would like the program to ask me for the 3 inputs, like :
Enter data set x1,y1 :
Enter data set x2,y2 :
Enter data set x3,y3 :
The calculation would be
y1=A+Bx1+C/x1
y2=A+Bx2+C/x2
y3=A+Bx3+C/x3
And then return A=....., B=....., C=.....,
Thank you in advance.
Dimitris

답변 (2개)

Yongjian Feng
Yongjian Feng 2021년 11월 24일
Try it yourself first, and we can then help to improve your work. Your task can be broken down into the following subtask:
  1. Reading user input: https://www.mathworks.com/help/matlab/ref/input.html
  2. Solve equations: https://www.mathworks.com/help/symbolic/solve.html#d123e272541

Dimitris Gkoutzamanis
Dimitris Gkoutzamanis 2021년 11월 24일
Thank you Feng! I think I did it:)
prompt = 'Enter x1: ';
x1 = input(prompt)
prompt = 'Enter y1: ';
y1 = input(prompt)
prompt = 'Enter x2: ';
x2 = input(prompt)
prompt = 'Enter y2: ';
y2 = input(prompt)
prompt = 'Enter x3: ';
x3 = input(prompt)
prompt = 'Enter y3: ';
y3 = input(prompt)
syms A B C
eqns = [A + B*x1 + C/x1 == y1, A + B*x2 + C/x2 == y2, A + B*x3 + C/x3 == y3];
S = solve(eqns,[A B C])

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by