Filter löschen
Filter löschen

Wrong answer for sine function

1 Ansicht (letzte 30 Tage)
Ellen Brown
Ellen Brown am 17 Nov. 2019
Kommentiert: Star Strider am 17 Nov. 2019
I am trying to create a function to evaluate sine at different values of t
function F = rforce(t)
F = 0.3 + 0.2.*sin(2.*pi.*t/365 - pi/2);
end
but this gives the incorrect answer when ran in matlab
  2 Kommentare
Star Strider
Star Strider am 17 Nov. 2019
It would appear that the units of ‘t’ are days, so ‘F’ would be with respect to years (or fractions of years).
What result do you want?
Ellen Brown
Ellen Brown am 17 Nov. 2019
I want F in respect to days, how would I do this?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 17 Nov. 2019
Define ‘t’ in terms of days (or fractions of days).
Try this:
rforce = @(t) 0.3 + 0.2.*sin(2.*pi.*t/365 - pi/2);
tdays = 1:0.25:365.25; % One Year in 6-Hour Increments
figure
plot(tdays, rforce(tdays))
grid
xlabel('Days')
ylabel('r Force')
xlim([min(tdays) max(tdays)])
  2 Kommentare
Ellen Brown
Ellen Brown am 17 Nov. 2019
thank you!
Star Strider
Star Strider am 17 Nov. 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by