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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% 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 comentario
Mathieu NOE
el 1 de Oct. de 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.
Respuestas (1)
Chunyu Xiao
el 1 de Oct. de 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)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!