Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

is my solution wrong?

2 visualizzazioni (ultimi 30 giorni)
Mohammad Adeeb
Mohammad Adeeb il 10 Mar 2018
Chiuso: MATLAB Answer Bot il 20 Ago 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 Commenti
Geoff Hayes
Geoff Hayes il 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 il 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.

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by