Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

is my solution wrong?

2 Ansichten (letzte 30 Tage)
Mohammad Adeeb
Mohammad Adeeb am 10 Mär. 2018
Geschlossen: MATLAB Answer Bot am 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 Kommentare
Geoff Hayes
Geoff Hayes am 10 Mär. 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 am 10 Mär. 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.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by