11. Create a program to implement the Newton-Raphson method for finding roots of a function.
Required Input:
Function: f(x) = x^3 - 2x - 5
Derivative: f'(x) = 3x^2 - 2
Initial Guess: x0 = 2
Expected Output:
Root: 2.0946
Code In R
newton_raphson <- function(f, f_prime, x0, tol) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output
12. Create a custom function to compute the spectral clustering of a graph.
Required Input:
Adjacency Matrix:
[,1] [,2] [,3]
[1,] 0 1 1
[2,] 1 0 1
[3,] 1 1 0
Expected Output:
Cluster assignments: 1, 2, 1
Code In R
spectral_clustering <- function(adj_matrix, k) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output
13. Write an R program to calculate the PageRank of nodes in a graph using an iterative method.
Required Input:
Adjacency Matrix:
[,1] [,2] [,3]
[1,] 0 1 1
[2,] 1 0 1
[3,] 1 1 0
Expected Output:
PageRank Scores: 0.3333 0.3333 0.3333
Code In R
calculate_pagerank <- function(adj_matrix, damping_factor, tol) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output
14. Write a function to fit a logistic regression model manually using gradient descent.
Required Input:
Data Frame:
x y
1 1 0
2 2 0
3 3 1
4 4 1
Expected Output:
Fitted Coefficients: -5.6964 2.3867
Code In R
logistic_regression <- function(df, lr, iterations) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output
15. Implement a custom function to calculate bootstrapped confidence intervals for the mean of a dataset.
Required Input:
Dataset: c(5, 7, 9, 11, 13)
Bootstrap Samples: 1000
Confidence Level: 95%
Expected Output:
Confidence Interval: 6.6, 11.4
Code In R
bootstrap_ci <- function(data, num_samples, conf_level) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output
16. Implement a function to solve constrained optimization problems using the Lagrange multiplier method.
Required Input:
Objective Function: f(x, y) = x^2 + y^2
Constraint: g(x, y) = x + y - 1 = 0
Expected Output:
Optimal Solution: x = -3.802555e+42 , y = -2.459376e+42
Code In R
lagrange_optimization <- function(f, g, start) {
# Your logic here
}
# Call the function
Run Code?
Click Run Button to view compiled output