part1:
the given inequality is x1+x2+x3+........+xk<=n
we can say that x1+x2+x3+....+xk can be n,n-1,n-2,........,3,2,1,0 according to the given inequality.
The no of non negative solutions will be (n+k-1)Ck-1 when r.h.s=n
The no of non negative solutions will be (n+k-2)Ck-1 when r.h.s=n-1
The no of non negative solutions will be (n+k-3)Ck-1 when r.h.s=n-2
..........................................................................................................
...........................................................................................................
The no of non negative solutions will be (k)Ck-1 when r.h.s=1
The no of non negative solutions will be (k-1)Ck-1 when r.h.s=0
So total no of non negative solutions will be
=(k-1)Ck-1+ (k)Ck-1+ .................+(n+k-3)Ck-1+(n+k-2)Ck-1+(n+k-1)Ck-1
=(n+k)Ck (We know that (r)Cr+ (r+1)Cr+ .................+(n-3)Cr+(n-2)Cr+(n-1)Cr+(n)Cr=(n+1)C(r+1).....combination formula)
Now we are going to code it out in python to find (n+k)Ck
python code snippet:>
![In [1] : import numpy as np from scipy.special import comb def cumulative comb with repetition (n, k): #using comb () functio](http://img.homeworklib.com/questions/5e3bd150-0506-11eb-8345-0b518573fdaf.png?x-oss-process=image/resize,w_560)
text code:>
import numpy as np
from scipy.special import comb
def cumulative_comb_with_repetition(n,k):
#using comb() function to calculate
(n+k)C(k)
return comb(n+k,k)
#getting the no of non negative solutions for x1+x2+x3<=5
print(cumulative_comb_with_repetition(5,3))
#getting the no of non negative solutions for
x1+x2+x3+x4<=6
print(cumulative_comb_with_repetition(6,4))
output:>
56.0
35.0
Hope the solution is useful.If you have any problem regarding the answer,then comment down below.
import numpy as np from scipy.special import comb def cumulative_comb_with_repetition(n, k): """ Compute the number of...
def stochastic_gradient_descent(feature_matrix, label,
learning_rate = 0.05, epoch = 1000):
"""
Implement gradient descent algorithm for regression.
Args:
feature_matrix - A numpy matrix describing the given data, with
ones added as the first column. Each row
represents a single data point.
label - The correct value of response variable, corresponding to
feature_matrix.
learning_rate - the learning rate with default value 0.5
epoch - the number of iterations with default value 1000
Returns: A numpy array for the...
def gradient_descent(feature_matrix, label, learning_rate =
0.05, epoch = 1000):
"""
Implement gradient descent algorithm for regression.
Args:
feature_matrix - A numpy matrix describing the given data, with
ones added as the first column. Each row
represents a single data point.
label - The correct value of response variable, corresponding to
feature_matrix.
learning_rate - the learning rate with default value 0.5
epoch - the number of iterations with default value 1000
Returns: A numpy array for the...
Problem 5 (5 points) Given an integer number, n, create a n by n matrix that has values 0 to n- Use the built-in NumPy methods to solve this problem. You can solve this problem in one line In [ ]: def np1(n): # YOUR CODE HERE raise NotImplementedError) Expected output: np1(2) yields [[0,1],[2,3]] np1(3) yields ([[e, 1, 2], 3, 4, 51 Use the cell below to test your function In : np1(2)
PYTHON
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
Our goal is to create a linear regression model to estimate
values of ln_price using ln_carat as the only feature. We will now
prepare the feature and label arrays.
"carat" "cut" "color"
"clarity" "depth" "table"
"price" "x" "y" "z"
"1" 0.23 "Ideal" "E" "SI2" 61.5 55 326
3.95 3.98 2.43
"2" 0.21 "Premium" "E" "SI1"...
Undecimal to decimal&decimal to undecimal
#Your code here
Thank you!
Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...
NEED HELP WITH PROBLEM 1 AND 2 OF THIS LAB. I NEED TO PUT IT
INTO PYTHON CODE! THANK YOU!
LAB 9 - ITERATIVE METHODS FOR EIGENVALUES AND MARKOV CHAINS 1. POWER ITERATION The power method is designed to find the dominant' eigenvalue and corresponding eigen- vector for an n x n matrix A. The dominant eigenvalue is the largest in absolute value. This means if a 4 x 4 matrix has eigenvalues -4, 3, 2,-1 then the power method...
Python Programming (Just need the
Code)
Index.py
#Python 3.0
import re
import os
import collections
import time
#import other modules as needed
class index:
def __init__(self,path):
def buildIndex(self):
#function to read documents from
collection, tokenize and build the index with tokens
# implement additional
functionality to support methods 1 - 4
#use unique document integer
IDs
def exact_query(self, query_terms, k):
#function for exact top K retrieval (method 1)
#Returns...