Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Return the max, min, and zeros of a function y, and plot it.
#R version 3.3.2 # Return the max, min, and zeros of a function y, and plot same. library(ggplot2) # Define some constants first pi=3.1416 b=(2*pi)/365.2422 c=-79.5*b # y is the solar declination function f(d) where d is the day of year d=seq(0,365,1) y=23.4368*sin((b*d)+c) cat("The max. of y is", max(y), "and occurs at index x =", which.max(y), "\n") cat("The min. of y is", min(y), "and occurs at index x =", which.min(y), "\n") # Search the function output vector y for zeros and return exact zero(s), or # a pair of adjacent values between which a zero exists. cat("Searching for the zero points in vector y...\n") for(i in 2:length(y)) { test=abs(sign(y[i-1])+sign(y[i])); if(test==0) { cat("x.indexes",i-1,i,"y.values",y[i-1],y[i],"\n") }; if(test==1 && y[i]==0) { cat("x.index",i,"y.value",y[i],"\n") }; } # Now plot the function title1="Solar Declination by Day of Year" qplot(d,y,geom="path",main=title1,xlab="Day of Year",ylab="Solar Declination")+ scale_x_continuous(breaks=seq(0,365,73))+scale_y_continuous(breaks=seq(-25,25,5))+ geom_line(aes(x=80.5,y=y),color="green")+geom_line(aes(x=263,y=y),color="orange")+ geom_line(aes(x=172,y=y),color="yellow")+geom_line(aes(x=354,y=y),color="blue")+ annotate("text",x=c(36,126,217,308),y=-5,label=c("Winter","Spring","Summer","Fall")) # Done.
run
|
edit
|
history
|
help
0
R added
Grad-sistemac
matrix
26-08-2020AjusteCurvaLinearizab
Random Forest Example
Mathematical operations 1
Ex-02-02-21
Área de un cuadrado
EulerSIR
SEIR-Modell