## How to solve equation

on 7 Nov 2012

### Walter Roberson (view profile)

I have

```a = [1 2 3 4]; b = [2 3 4 5];
(X*a - 5)^2 + (X*b - 6)^2 + (X - 4)^2 - 16 =  0
```

How to create this 4 equations and find the value of 'X' for each equation in MATLAB..?

## Products

No products are associated with this question.

### Walter Roberson (view profile)

on 7 Nov 2012
Edited by Walter Roberson

### Walter Roberson (view profile)

on 7 Nov 2012

```arrayfun( @(A, B) roots([B^2+A^2+1, -12*B-10*A-8, 61], a, b, 'Uniform', 0)
```

Alternate approach that reaches the answer you want but with a different sequence of steps:

```syms A B X
x = solve((X*A - 5)^2 + (X*B - 6)^2 + (X - 4)^2 - 16, X);
subs(x, {A, B}, {a, b})
```

This finds the generalized solution as a single equation, and then puts the actual values in, which is the reverse of the steps you asked.

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi