Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

is my solution wrong?

2 vues (au cours des 30 derniers jours)
Mohammad Adeeb
Mohammad Adeeb le 10 Mar 2018
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaires
Geoff Hayes
Geoff Hayes le 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 le 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.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by