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

4 次查看(过去 30 天)
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 个评论
RICCARDO CASET
RICCARDO CASET 2022-7-29
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 2022-7-29
编辑:RICCARDO CASET 2022-7-29
I attached the code in the comments. Sorry it's the first time using these applicatives!

请先登录,再进行评论。

采纳的回答

Voss
Voss 2022-7-29
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

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by