R programming
1. Write an assignment statement to complete each of the following without using diff() and sign(): (a) generate a vector of the difference between the ith element and the (i+1)th element in a vector v of integers, where i = 1: length(v), and (b) generate a vector of the sign of each elements in the vector generated in (a) as follows: ‘p’ for positive, ‘n’ for negative. (Use v ⟵ c(1,4,7,2,1) for testing.)
2. Write a function that assigns an integer value, say 7, to an integer n and generate a symmetric metrics where the diagonal elements are all zeros, and the elements following the 0 value are consecutive odd numbers. For example, the first row of a 5X5 matrix contains “0, 1, 3, 5, 7”; the second row contains “1, 0, 3, 5, 7”. You may use any function that we have used in our lectures to write your function. (You cannot hard-code the matrix; it needs to be generated.)
1.
SOURCE CODE:
v=c(1,4,7,2,1)
ans=c()
for(i in 1:length(v)){
if(i+1<=length(v))
ans=c(ans,(v[i]-v[i+1]))
}
print(ans)
ans2=c()
for(i in 1:length(ans)){
if(ans[i]<0)
ans2=c(ans2,'n')
else
ans2=c(ans2,'p')
}
print(ans2)
SCREENSHOTS:


2.
SOURCE CODE:
library(R.utils)
n=7
tup=c()
i=1
while(i!=n+2)
{
tup=c(tup,i)
i=i+2
}
len=length(tup)+1
m=matrix(,nrow=0,ncol=len)
for (i in 1:len)
{
temp=insert(tup,at=i,values=0)
m=rbind(m,temp)
}
print(m)
SCREENSHOTS:


R programming 1. Write an assignment statement to complete each of the following without using diff()...
In Matlab write a script that does the following. 1. Creates a row vector v = [3, 6, 9, 9, 15], and then manipulates v to create each of the following vectors (and then displays the result of each): (a) a = [9, 36, 81, 81, 225] (b) b = [ 1 3 , 1 6 , 1 9 , 1 9 , 1 15 ] (c) c = [1, 2, 3, 3, 5] (d) d = [15, 9, 9,...
Matlab code
4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
Problem 1 (10 pts) (Matlab coding) In this problem you will be manipulating a sine wave plot using a for loop and if statements. a) Create a vector x that goes from −4π to 4π with increments of π/10. b) Instead of using y = sin(x) on the entire array at once, use a for loop to calculate the sine of x for each value in the vector individually. Vector y should be the sine of vector x. Use the...
Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for cond(). (4) Calculate the inverse of tmp. See help...
Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for cond(). (4) Calculate the inverse of tmp. See help...
Please write a C++ Program for the following problem >> Vector: Calculation the sum of each two adjacent Numbers.... >>【Description】 Read integer numbers from keyboard and store them into a vector. Calculation the sum of each two adjacent Numbers, store the result into another vector. Then output the result inversely. For example, if the input is 1 2 3 4 5 then the output is 9 7 5 3 【 Input】 There are 5 test cases. For each case, there...
The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...
can i get some help with this program
CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...
1. Write a function in matlab platform for each part as described. a. Obtains the multiplication of elements of n-sized vector, where n is a positive integer. Name of this function must be “all2”. b. Obtains the sum of elements of nxn-sized matrix, where n is a positive integer. Name of this function must be “will3”. c. Obtains the sum of prime factors of an integer. Name of this function must be “be0”. Example (1): Prime factors of 84 are...
This assignment assesses the material covered in Modules 6-10. Write full and complete so- lutions, using full sentences where appropriate. Explain all row operations when computing an RREF. Answer the questions asked. Questions 1-5 are worth 20 points each. The bonus question is worth 10 points (but points on this assignment are capped at 100). Recommended Deadline: April 24th Final Deadline: May 1st. 1. Compute the inverse of the matrix A = 1 3 1 4 -1 1 2 0...