Matlab keeps giving me error for invalid syntax! I don't understand why

1 view (last 30 days)
I wrote this programm, Matlab keeps giving me error in line 38.
The programm is about finding and providing solutions, if they exist, of a generic quadratic equation.
  2 Comments
RICCARDO CASET
RICCARDO CASET on 29 Jul 2022
clear
clc
a=input('Inserisci valore di a, a=');
b=input('Inserisci valore di b, b=');
c=input('Inserisci valore di c, c=');
%Controllo che i coefficienti siano diversi da 0
d=(b^2)-4*(a*c);
A=-b/(2*a);
A1=-b+sqrt(d)/(2*a);
A2=-b-sqrt(d)/(2*a);
%ora che il delta è stato calcolato devo presentare i vari casi per le
%soluzioni
if d<0
fprintf('Non esiste soluzione nel campo dei reali \n')
else
if d==0
fprintf('La soluzione unica e'' %12.2f \n', A)
else
if d>0
fprintf('Le soluzioni distinte sono %12.2f \n' A1, A2)
end
end
end
RICCARDO CASET
RICCARDO CASET on 29 Jul 2022
Edited: RICCARDO CASET on 29 Jul 2022
I attached the code in the comments. Sorry it's the first time using these applicatives!

Sign in to comment.

Accepted Answer

Voss
Voss on 29 Jul 2022
Missing comma:
% fprintf('Le soluzioni distinte sono %12.2f \n' A1, A2)
% ^ no comma
fprintf('Le soluzioni distinte sono %12.2f \n', A1, A2)
% ^ comma

More Answers (1)

Jonas
Jonas on 29 Jul 2022
looks like you are missing a comma
if d>0
fprintf('Le soluzioni distinte sono %12.2f \n',A1 , A2)
end

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!