Writing a problem for a sine wave?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nick Haufler
am 5 Okt. 2015
Beantwortet: Image Analyst
am 5 Okt. 2015
For the attached document, can someone look at my code. Im confused as if I got the equation right or not.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 5 Okt. 2015
Nick:
You only need Est, not Est(1) because Est is not an array - it's a scalar. Also, don't assign Est to x as the first line because there is no x yet. And you need to initialize Est to x, not 1, AFTER you get x.
N=input('Please enter how many terms you would like to go out:')
x=input('Please enter the angle in radians:')
Est=x;
for k= 2:N
termK = (-1)^(k-1)*x^(2*k-1)/factorial(2*k-1);
Est = Est + termK;
fprintf('Term %d = %.6f, so now Est = %.6f\n', k, termK, Est);
end
fprintf('The final Estimated Value = %.6f\n', Est)
fprintf('Actual Value of sin(%.6f) = %0.6f\n', x, sin(x))
fprintf('Difference is %0.6f\n', Est-sin(x))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!