필터 지우기
필터 지우기

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

추가 답변 (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에서 Waveform Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by