Question

**Question #15.** Write a function file that
determines the following sum using a **for** loop:

*y=**i=1**n**(3-2i)**2*

Use n as input and test the function for n=100.

**Question #15.** Write a function file that
determines the following sum using a **for** loop:

*y=**i=1**n**(3-2i)**2*

Use n as input and test the function for n=100.

Answer #1

**SOLUTION -**

**15 )**

**CODE -**

function y = perform(n)

y = 0;

% looping from 1 to n

for i = 1:n

% adding each term to y

y += (3 - 2*i)^2;

end

end

% sample run

y = perform(100)

**SCREENSHOT-**

**OUTPUT**

**IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------**

Consider the following function:
double arrayavg(int a[], int n){
int sum=0;
for(int i=0; i!=n; ++i){
sum+=a[i];
}
return (double)sum/n;
}
Rewrite the function to eliminate the array subscripting (a[i]),
using pointer arithmatic instead.
Write a program that reads a line of input and checks if it is
a palindrome (ignoring spaces)
Write a program that takes the name of a file as a command line
argument, and prints the contents of the file (similar to the linux
'cat' program).
Write...

Using MATLAB
Write a user-defined MATLAB function for the following math
function:
y(x)= (-0.2x^3 + 7x^2)e^-0.3x
The input to the function is x and the output is y. Write the
function such that x can be a vector (use element-by-element
operations).
(a) Use the function to calculate y(-1.5) and y(5).
(b) Use the function to make a plot of the function y(x) for -2
≤ x ≤ 6.

IN C++ AS SIMPLE AS POSSIBLE ______
Re-write the given function,
printSeriesSquareFifth, to
use a while loop (instead of for).
• The function takes a single integer n as a
parameter
• The function prints a series between 1 and
that parameter, and also prints its result
• The result is calculated by summing the numbers between 1 and
n (inclusive). If a number is divisible by 5, its
square gets added to the result instead.
• The function does not...

1.Consider the function represented in sum of product form as
F(x, y, z)=∑(0,1,4,6). Write the function F in product of sum form
and minimize it using K-map.
2. Design a digital circuit (with minimum number of gates) with
input ? = ?3?2?1?0 and an output ?. The output F should be 1 if A
is divisible by either 2 or 3.

Question 1
Write functions that do the following:
i) A function that takes 2 arguments and adds them. The result
returned is the sum of the parameters.
ii) A function that takes 2 arguments and returns the
difference,
iii) A function that calls both functions in i) and ii) and
prints the product of the values returned by both.
Question 2
Write functions:
i) One that prompts a user for 2 numbers.
ii) Adds the two numbers if they are...

Question 4 MATLAB
a) Write a function file called q4.m containing the following
nonlinear equations. ?(?1?2 ) = ?1 2 + ?2 2 − 26
?(?1?2 ) = 3?1 2 + 25?2 2 − 100 (1 Mark)
b) Use MATLAB’s FSOLVE operator to solve these equations with x1
= 2 and x2 = 2 as your starting point. How many iterations did
MATLAB use to solve them? (1 Mark)

1) Write an algorithm to calculate the sum of the
following series:
Sum =x-x3/3!
+ x5/5! – x7/7! +……. Stop when
the
term<0.0001.
2) An internet service provider charges
its subscribers per month as follows:
Data usage
(n), in
gbs
charges (NIS)
0.0<n<=1.0
250
1.0<n<=2.0
500
2.0<n<=5.0
1000
5.0<n<=10.0
1500
n>10
2000
Write a C program
to read the usage(n) from a file and print the charges to be paid
by...

Arrays, loops, functions: Lotto
Element Repeated Function
Write a function that that takes as parameters an array of ints,
an int value named element, and an int value named end. Return a
bool based on whether the element appears in the array starting
from index 0 and up to but not including the end index.
Generate Random Array
Write a function that takes as parameters an array of integers
and another integer for the size of the array. Create a...

Problem 3. Let n ∈ N. Prove, using induction, that Σi^2= Σ(n + 1
− i)(2i − 1). Note: Start by expanding the righthand side, then
look at the following pyramid (see link) from

By using the R-Studio answer the following question:
1. a) write a simple loop to list the squares of the first 10
integers.
b) Generate the 10*10 matrix A, whose (i;j) entry is
sin(2*pi*(i-j))

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 6 minutes ago

asked 12 minutes ago

asked 42 minutes ago

asked 44 minutes ago

asked 46 minutes ago

asked 51 minutes ago

asked 57 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago