## exact multiplication of variable in equation

### Shivkumar Meena (view profile)

on 10 Feb 2019
Latest activity Commented on by John D'Errico

on 10 Feb 2019

### John D'Errico (view profile)

I want my output as s^2-5*s+6
but i am getting
syms s
p=[2 3];
q=s-p;
prod(q);
Ans (s-2)*(s-3)

### John D'Errico (view profile)

on 10 Feb 2019

But that IS the exact answer, the correct answer. Did you want MATLAB to produce the wrong answer?
Maybe what you wanted is for MATLAB to "expand" that product? Did you tell MATLAB to do so? How might you do that?
What would the result be if you tried this?
expand(prod(q))
Its just a thought.
A good way to learn about the tools in MATLAB is to read about all of the functions in a toolbox. Kind of like reading the manual.

Shivkumar Meena

### Shivkumar Meena (view profile)

on 10 Feb 2019
I know that matlab is giving correct answer but I want it in expanded form.
how i can get my answer in format of numerator polinomial/denominator polinomial.
syms s
p=[2 3];
r=s-1;
q=s-p;
s=2*(z-1)/(z+1);
subs(q)
expand(prod(q))
%a=r/expand(prod(q));
ans=((2*z - 2)/(z + 1) - 1)/((2*z - 2)^2/(z + 1)^2 - (5*(2*z - 2))/(z + 1) + 6)
Walter Roberson

on 10 Feb 2019
numden()
John D'Errico

### John D'Errico (view profile)

on 10 Feb 2019
By the way, assigning something to the variable ans is a really bad idea, since ans will get overwritten by MATLAB.
Really, I think you need to spend some time reading the getting started tutorials. Learn how to assign results to variables. But mostly, you need to slow down. When I look at what you have typed there, I see several lines that do nothing, a variable z introduced from out of the blue.
Here, you have now created a rational polynomial, by some computation that I've not been told what it is.
ratpoly = ((2*z - 2)/(z + 1) - 1)/((2*z - 2)^2/(z + 1)^2 - (5*(2*z - 2))/(z + 1) + 6);
It is a rather messy thing.
pretty(ratpoly)
2 z - 2
------- - 1
z + 1
--------------------------
2
(2 z - 2) 10 z - 10
---------- - --------- + 6
2 z + 1
(z + 1)
Now it seems you want to simplify that mess.
simplify(ratpoly)
ans =
-(- z^2 + 2*z + 3)/(4*(z + 5))
But really, you are going too fast. SLOW DOWN. Learn to use MATLAB. Verify every line of code that you write. Make sure you know what each line did, and that it gave the result you expect. Otherwise, you will have all sorts of random crap, and not know where it came from.