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

2 ビュー (過去 30 日間)
RICCARDO CASET
RICCARDO CASET 2022 年 7 月 29 日
コメント済み: Voss 2022 年 7 月 29 日
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
  2 件のコメント
RICCARDO CASET
RICCARDO CASET 2022 年 7 月 29 日
thanks bro, you saved me
Voss
Voss 2022 年 7 月 29 日
You're welcome!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeWaveform Generation についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by