New to Matlab, need help

1 vue (au cours des 30 derniers jours)
Christopher
Christopher le 17 Déc 2013
Commenté : kei hin le 19 Déc 2013
Hi,
I'm really new to Matlab and I need some help with my homework. We are supposed to write a script/program that determines the zeros of a second degree polynomial function.
All I have so far is the basic structure:
a=input('Koeffizient a: ');
b=input('Koeffizient b: ');
c=input('Koeffizient c: ');
d=b^2-4ac
if d>0
x1=(-b+d)/2a;
x2=(-b-d)/2a;
if d=0
-(b/2a)
d<0
Fehler
end
end
disp('Nullstelle ist: ')
I would appreciate any help (especially those in the form of pointers to help me solve the problem myself and not get you guys to do my homework :P )

Réponse acceptée

kei hin
kei hin le 17 Déc 2013
Modifié(e) : kei hin le 17 Déc 2013
Operators can't be omitted. If 'a=2', you want '4',then you need '2*a', not '2a'. And you'd better type your code in Matlab, you will see the tips or warning message from the Matlab to correct your code.
for 'disp' help
You can also type 'doc' in matlab command window, then search something you want to know.
  1 commentaire
Walter Roberson
Walter Roberson le 17 Déc 2013
Remember to include () if needed. You probably want to divide by (2*a) rather than to divide by 2 and then multiply the result by a.

Connectez-vous pour commenter.

Plus de réponses (1)

Christopher
Christopher le 17 Déc 2013
Modifié(e) : Christopher le 17 Déc 2013
I've worked on it a little more, but my main problem seems to be around the d>=0 part. Any tips?
if true
% code
end
a=input('Koeffizient a eintippen: ');
b=input('Koeffizient b eintippen: ');
c=input('Koeffizient c eintippen: ');
d=(b*b)-(4*a*c);
if d>=0
x1=(-b+d)/(2*a);
if x1 ~=0;
disp (x1)
disp('ist eine Nullstelle');
end
x2=(-b-d)/(2*a);
if x2 ~=0;
disp (x2)
disp('ist eine Nullstelle');
end
x3=-(b/(2*a));
if x3 ~=0;
disp (x3)
disp('ist eine Nullstelle');
end
else disp ('keine Loesung')
end
  1 commentaire
kei hin
kei hin le 19 Déc 2013
what do you want?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by