Issue
I am very new on R progrraming language, I try to write function as a below
I tried to write code same as matlab but I think it is wrong.
How I should write this function in R language ?
I also need plot of the function between range 0 and 600.
I would be glad if you can help with this.
Thank you.
Solution
You mean, you just want to define a function(x)
which would return y
as defined in your above formula? Then use something like
## Define your function:
f <- function(x, w0 = 2.5, E = 50000, I = 30000, L = 600) {
return(w0 / (120*E*I*L) * (-x^5 + 2 * L^2 * x^3 - L^4 * x))
}
## Plot for x from 0 to 600:
x <- 0:600
plot(f(x) ~ x, type = "l")
Note that you may use your constant values w0, E, I, L
as parameters in your function (useful in case they would not be really constant :-)), and that you can give them default values.
Answered By – Philopolis
Answer Checked By – Candace Johnson (BugsFixing Volunteer)