MATLAB Answers

0

Wrong answer for sine function

Asked by Ellen Brown on 17 Nov 2019 at 20:09
Latest activity Commented on by Star Strider
on 17 Nov 2019 at 21:01
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 Comments

Star Strider
on 17 Nov 2019 at 20:16
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 on 17 Nov 2019 at 20:18
I want F in respect to days, how would I do this?

Sign in to comment.

1 Answer

Answer by Star Strider
on 17 Nov 2019 at 20:24
 Accepted Answer

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 Comments

Ellen Brown on 17 Nov 2019 at 20:56
thank you!
Star Strider
on 17 Nov 2019 at 21:01
As always, my pleasure!

Sign in to comment.