for eqn y=x^2 +bx +c, I have a known variable matrix for y. How can I find the value of x for corresponding different value of y in matrix?

4 views (last 30 days)
% we know how to find the value of x by varying x using linspace and calculating corresponding value of y.
% But the problem is that i know the 50 different value of y and i have to find corresponding value of x. How can i do that?
load value_y
y=x.^2+b*x+c;
  1 Comment
Mathieu NOE
Mathieu NOE on 1 Oct 2021
hello
this is not a matlab question
this is solving a second order polynomial equation - put the resolution method in a unction and apply it to your y data (array)
A second degree polynomial, also referred as a quadratic equation can be expressed as below:
ax² + bx + c = 0
to solve the equation we can use the quadratic formulas as shown below:
x1 = (-b + sqrt(b²-4ac))(2a)
x2 = (-b - sqrt(b²-4ac))/(2a)
a quadratic equation has two solutions when b²-4ac > 0
a quadratic equation has only one solution when b²-4ac = 0
a quadratic equation has no solution when b²-4ac < 0
Example (2 solutions)
2x²+ 6x + 1 = 0
b²-4ac = 62-4 x 2 x 1 = 28, since 28 > 0, we can conclude that there exists two solutions
x1 = (-b + (b²-4ac)1/2)/2a = -0.177
x2 = (-b - (b²-4ac)1/2)/2a = -2.822
Example (1 solutions)
3x² + 6x + 3 = 0
b²-4ac = 62-4 x 3 x 3 = 0, thus we can conclude that there only exists one solution
x = -b/2a = -1
How to construct a quadratic equation when its solutions are given
if x1 = 3 and x2 = 2, then we can construct the equation as shown below:
p(x) = (x - x1)(x - x2) = (x - 3)(x - 2) = x² - 5x + 6 = 0.

Sign in to comment.

Answers (1)

Chunyu Xiao
Chunyu Xiao on 1 Oct 2021
You can use roots to solve the problem:
% example
b = 2;
c = -3;
N = 50;
y = (1:N)';
x = zeros(N,2);
for k = 1:N
x(k,:) = roots([1,b,c-y(k)]);
end
table(y,x)
ans = 50×2 table
y x __ __________________ 1 -3.2361 1.2361 2 -3.4495 1.4495 3 -3.6458 1.6458 4 -3.8284 1.8284 5 -4 2 6 -4.1623 2.1623 7 -4.3166 2.3166 8 -4.4641 2.4641 9 -4.6056 2.6056 10 -4.7417 2.7417 11 -4.873 2.873 12 -5 3 13 -5.1231 3.1231 14 -5.2426 3.2426 15 -5.3589 3.3589 16 -5.4721 3.4721

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!