Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

is my solution wrong?

2 visualizaciones (últimos 30 días)
Mohammad Adeeb
Mohammad Adeeb el 10 de Mzo. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentarios
Geoff Hayes
Geoff Hayes el 10 de Mzo. de 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 el 10 de Mzo. de 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.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by