Info

This question is closed. Reopen it to edit or answer.

is my solution wrong?

4 views (last 30 days)
Mohammad Adeeb
Mohammad Adeeb on 10 Mar 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
close all;
clear all; %#ok<*CLSCR>
clc;
syms r z;
p1=input('specify the pol cofficent');
s=input('specify the operation','s');
p2=input('specify the second poly');
L_1=length(p1);
L_2=length(p2);
L=abs(L_1 - L_2);
if L_1>L_2
z=zeros(1,L_2);
A=[z p2];
end;
if L_1<L_2
z=zeros(1,L_1);
A=[z p1];
end;
hold on;
while s~='=';
if s=='+'
r= p1+p2;
elseif s=='-';
r= p1-p2;
elseif s=='*';
r= p1.*p2;
elseif s=='/';
r=p1./p2;
elseif s=='=';
print(r)
end;
ezplot(r,[-2,2]);
end;
hold off;
if s=='=';
r = pol_1;
end;
ezplot (r,[-2,2]);
  2 Comments
Geoff Hayes
Geoff Hayes on 10 Mar 2018
Mohammad - what are your inputs? what is the solution given by your code?
Your use of a while loop seems suspect. It seems that you might get stuck in the loop if the character string s is not '='. Also, try to avoid using equality (i.e. ==) for string comparisons. Instead use strcmp or strcmpi.
John D'Errico
John D'Errico on 10 Mar 2018
Surely you can test your solution. Code that is wrong produces errors. It produces strange, unexpected results. So what do you think? Is it right?
Will your code work on two polynomials of different order?
Why do you create the variable A if you do not use it?
Is it correct that the product of two polynomials is the product of their coefficients?
There are lots of problems that I see here. So, yes, your solution is wrong.

Answers (0)

Community Treasure Hunt

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

Start Hunting!