spicy_springroll
spicy_springroll

Reputation: 1

How do I solve for X on Matlab when X is on both sides of the equation

Suppose i have an equation that looks like this: x = y + zx

I have the values for y and z, I want to calculate x. How would I do this on Matlab without having to solve for x on paper?

Probably a simple equation but I am new, thank you!

I tried just writing the equation out and coding disp(x), but of course it did not work.

Upvotes: 0

Views: 98

Answers (1)

FragileX
FragileX

Reputation: 637

The function fzero() will give you a numeric answer if you move all of one side of the equation over to the other side, so the first side is equal to zero.

y = 4;
z = 2;
% Move everything to the right side
zero_left_side = @(x)(y+z*x) - (x);

initial_guess = 1;
x_solution = fzero(zero_left_side, initial_guess);

Upvotes: 1

Related Questions