Question

1. Pi Constant (?): Pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, approximately equal to 3.14159. The number ? apppears in many formular across mathematics and physics. Your task is to implement the method pi that accept an integer (int data type). pi(n) should follow the Madhava of Sangamagrama formula and return a value based on the terms we provided in the summation. We assume that the input n will always a positive value. The method should NOT print anything to console. Here is the examples: \begin{equation*} \pi = \sqrt{12} \sum_{i=0}^{\infty} \frac{(-1)^i}{(2i+1)3^i} = \sqrt{12} (1 - \frac{1}{9} + \frac{1}{45} - \frac{1}{189} + ...) \end{equation*} \begin{tabular}{|c|c|} \hline n & pi(n) \\ \hline 1 & 3.4641016151377544 \\ 2 & 3.0792014356780038 \\ 3 & 3.156181471569954 \\ 4 & 3.1378528915956805 \\ 5 & 3.1426047456630846 \\ ... & ... \\ \hline \end{tabular} Note: we identify the first term of the summation when i = 0 and n = 1

          1. Pi Constant (?):
Pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, approximately equal to 3.14159. The number ?
apppears in many formular across mathematics and physics. Your task is to implement the method pi that accept an integer (int data
type). pi(n) should follow the Madhava of Sangamagrama formula and return a value based on the terms we provided in the summation.
We assume that the input n will always a positive value. The method should NOT print anything to console. Here is the examples:
\begin{equation*}
\pi = \sqrt{12} \sum_{i=0}^{\infty} \frac{(-1)^i}{(2i+1)3^i} = \sqrt{12} (1 - \frac{1}{9} + \frac{1}{45} - \frac{1}{189} + ...)
\end{equation*}
\begin{tabular}{|c|c|}
\hline
n & pi(n) \\
\hline
1 & 3.4641016151377544 \\
2 & 3.0792014356780038 \\
3 & 3.156181471569954 \\
4 & 3.1378528915956805 \\
5 & 3.1426047456630846 \\
... & ... \\
\hline
\end{tabular}
Note: we identify the first term of the summation when i = 0 and n = 1
        
Show more…
1. Pi Constant (?):
Pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, approximately equal to 3.14159. The number ?
apppears in many formular across mathematics and physics. Your task is to implement the method pi that accept an integer (int data
type). pi(n) should follow the Madhava of Sangamagrama formula and return a value based on the terms we provided in the summation.
We assume that the input n will always a positive value. The method should NOT print anything to console. Here is the examples:

    π = √(12)∑i=0^∞((-1)^i)/((2i+1)3^i) = √(12) (1 - (1)/(9) + (1)/(45) - (1)/(189) + ...)


n     pi(n) 

1     3.4641016151377544 

2     3.0792014356780038 

3     3.156181471569954 

4     3.1378528915956805 

5     3.1426047456630846 

...     ... 


Note: we identify the first term of the summation when i = 0 and n = 1

Added by Hannah B.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Place your code in a class named Calculus.java. Each class should contain a main method which should do the following: For the Calculus class: Implement the method pi to accept one integer parameter and return the value of the Pi constant value after the given term. Implement the method euler to accept one integer parameter and return the value of the Euler constant value after the given term. In the main method, use the for loop to iterate all terms and print constant values from: 1 to 30 for the pi method 1 to 18 for the euler method Pi value after 1 term(s) = 3.4641016151377544 Pi value after 2 term(s) = 3.0792014356780038 Pi value after 3 term(s) = 3.156181471569954 Pi value after 4 term(s) = 3.1378528915956805 Pi value after 5 term(s) = 3.1426047456630846 Pi value after 6 term(s) = 3.141308785462883 Pi value after 7 term(s) = 3.1416743126988376 Pi value after 8 term(s) = 3.141568715941784 Pi value after 9 term(s) = 3.141599773811506 Pi value after 10 term(s) = 3.1415905109380797 Pi value after 11 term(s) = 3.1415933045030813 Pi value after 12 term(s) = 3.1415924542876463 Pi value after 13 term(s) = 3.14159271502038 Pi value after 14 term(s) = 3.141592634547314 Pi value after 15 term(s) = 3.141592659521714 Pi value after 16 term(s) = 3.1415926517339976 Pi value after 17 term(s) = 3.1415926541725754 Pi value after 18 term(s) = 3.141592653406165 Pi value after 19 term(s) = 3.1415926536478262 Pi value after 20 term(s) = 3.1415926535714034 Pi value after 21 term(s) = 3.141592653595635 Pi value after 22 term(s) = 3.1415926535879337 Pi value after 23 term(s) = 3.1415926535903864 Pi value after 24 term(s) = 3.1415926535896035 Pi value after 25 term(s) = 3.141592653589854 Pi value after 26 term(s) = 3.141592653589774 Pi value after 27 term(s) = 3.1415926535897998 Pi value after 28 term(s) = 3.1415926535897913 Pi value after 29 term(s) = 3.141592653589794 Pi value after 30 term(s) = 3.1415926535897936 Euler value after 1 term(s) = 1.0 Euler value after 2 term(s) = 2.0 Euler value after 3 term(s) = 2.5 Euler value after 4 term(s) = 2.6666666666666665 Euler value after 5 term(s) = 2.708333333333333 Euler value after 6 term(s) = 2.7166666666666663 Euler value after 7 term(s) = 2.7180555555555554 Euler value after 8 term(s) = 2.7182539682539684 Euler value after 9 term(s) = 2.71827876984127 Euler value after 10 term(s) = 2.7182815255731922 Euler value after 11 term(s) = 2.7182818011463845 Euler value after 12 term(s) = 2.718281826198493 Euler value after 13 term(s) = 2.7182818282861687 Euler value after 14 term(s) = 2.7182818284467594 Euler value after 15 term(s) = 2.71828182845823 Euler value after 16 term(s) = 2.718281828458995 Euler value after 17 term(s) = 2.718281828459043 Euler value after 18 term(s) = 2.7182818284590455 1. Pi Constant Pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, approximately equal to 3.14159. The number TT appears in many formulas across mathematics and physics. Your task is to implement the method pi that accepts an integer (int data type). pi(n) should follow the Madhava of Sangamagrama formula and return a value based on the terms we provided in the summation. -1i T=12 (2i+1)3i 1 1 1 9 45 . 189 n pi(n)
Close icon
Play audio
Feedback
Powered by NumerAI
Kathleen Carty David Collins
Danielle Fairburn verified

Akash M and 58 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
complete-the-code-to-match-the-output-as-shown-in-below-sample-output-the-project-consists-of-the-following-class-files-complete-what-is-in-bold-in-java-loan-class-import-javautilrandom-loan-41538

LOAN CLASS import java.util.Random; /*Loan class serves as a part of Bank class to maintain loan information and to calculate monthly installments and total paid amount*/ public class Loan { private double annualInterestRate; private int numberOfYears; private double loanAmount; private java.util.Date loanDate; /* Default constructor */ public Loan() { Random ranValue = new Random(); this.annualInterestRate = ranValue.nextInt(1000)/100.0; loanDate = new java.util.Date(); } /* Construct a loan with specified annual interest rate, number of years, and loan amount */ public Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this.annualInterestRate = annualInterestRate; this.numberOfYears = numberOfYears; this.loanAmount = loanAmount; loanDate = new java.util.Date(); } /* Return annualInterestRate */ public double getAnnualInterestRate() { return annualInterestRate; } /* Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; } /* Return numberOfYears */ public int getNumberOfYears() { return numberOfYears; } /* Set a new numberOfYears */ public void setNumberOfYears(int numberOfYears) { this.numberOfYears = numberOfYears; } /* Return loanAmount */ public double getLoanAmount() { return loanAmount; } /* Set a new loanAmount */ public void setLoanAmount(double loanAmount) { this.loanAmount = loanAmount; } /* Find monthly payment */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 -(1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12))); return monthlyPayment; } /* Find total payment */ public double getTotalPayment() { double totalPayment = getMonthlyPayment() * numberOfYears * 12; return totalPayment; } /* Return loan date */ public java.util.Date getLoanDate() { return loanDate; } /* Set a new loan date */ public void setLoanDate(java.util.Date loanDate) { this.loanDate = loanDate; } } BANK CLASS import java.util.Random; import java.util.Scanner; /*Bank class maintains banks information.*/ public class Bank { private String bankName; private int bankCode; Loan loanInfo; /* constructor to create initial banks with names, codes, and loan information with annualInterestRate, and quote created date*/ Bank() { Random ranValue = new Random(); String bankNames[] = {"Wells Fargo","City Bank","Chase","Discovery","Terra Bank","PNC Financial Services","Capital One Financial"}; this.setBankName(bankNames[ranValue.nextInt(bankNames.length)]); this.bankCode = 1+ranValue.nextInt(99); loanInfo = new Loan(); } /* constructor to create each matched banks with bank's names, bank's codes, * and bank's loan information with bank's annualInterestRate, quote created date, user specified numberOfYears, user specified loanAmount * and prints the matched bank's bank name, bank code, AnnualInterestRate, loan amount, monthly payment, numberOfMonths, total payment, quote created date*/ Bank(Bank bank, double annualInterestRate, int numberOfYears, double loanAmount, BankFinder c){ this.setBankName(bank.bankName); this.bankCode = bank.bankCode; loanInfo = new Loan(annualInterestRate, numberOfYears, loanAmount); double monthlyPayment = loanInfo.getMonthlyPayment(); double totalPayment = loanInfo.getTotalPayment(); java.util.Date loanDate = loanInfo.getLoanDate(); System.out.printf("%-20s%-10d%-15.2f%-15.2f%-15.2f%-15d%-25.2f%-30s ", this.bankName, this.bankCode, annualInterestRate, loanAmount, monthlyPayment, numberOfYears*12, totalPayment, loanDate); } public static int howMany() { Scanner input = new Scanner(System.in); System.out.println("With how many banks do you want to check: "); return input.nextInt(); } public static void printBanksCodes(Bank banks[]) { for (Bank bank : banks) { System.out.println("Bank: " + bank.getBankName() + ", Code: " + bank.getBankCode() + ", Interest Rate: " + bank.getLoanInfo().getAnnualInterestRate() + ", Quote Date: " + bank.getLoanInfo().getLoanDate()); } }

Akash M.

in-java-language-chapter-8-programming-project-1-unlimited-tries-for-this-exercise-you-will-write-a-class-named-area-the-area-class-should-provide-static-methods-that-calculate-the-areas-of-88025

Chapter 8: Programming Project 1 For this exercise, you will write a class named Area. The Area class should provide static methods that calculate the areas of different geometric shapes. The class should have three overloaded static methods named getArea. Here is a description of each method: 1. The first version of the static getArea method will calculate the area of a circle. It should accept the circle's radius as a double and return the circle's area as a double. See the formula below for calculating the area of a circle. 2. The second version of the static getArea method will calculate the area of a rectangle. It should accept the rectangle's length and width as doubles and return the rectangle's area as a double. See the formula below for calculating the area of a rectangle. 3. The third version of the static getArea method will calculate the area of a trapezoid. It should accept the trapezoid's base #1 length, base #2 length, and height as doubles and return the trapezoid's area as a double. See the formula below for calculating the area of a trapezoid. The Area class should also have a main method that calls each of the overloaded getArea methods. It should display the following values, each on a separate line: 1. The area of a circle with a radius of 3. The value should be rounded to two decimal places. 2. The area of a rectangle with a length of 2 and a width of 4. The value should be rounded to one decimal place. 3. The area of a trapezoid with base lengths of 3 and 4, and a height of 5. The value should be rounded to one decimal place. Here are the formulas for calculating the areas of the shapes: - Area of a circle: Area = πr², where π is Math.PI and r is the circle's radius. - Area of a rectangle: Area = Width × Length - Area of a trapezoid: Area = (base1 + base2) × height / 2

Supreeta N.

exercise-2-now-let-us-consider-the-following-dierential-equation-dy-dt-1-2-y-2-t-y0-1-we-solve-the-above-equation-to-t-2-using-the-euler-method-write-a-script-file-eulernm-that-computes-the-15184

Exercise 2. Now, let us consider the following differential equation: dy/dt = (1/2)y + 2t, y(0) = 1. We solve the above equation for t = 2 using the Euler method. Write a script file eulerN.m that computes the Euler approximation to the above differential equation using a step size of h = 2/N and step number of N. That is to say, if you run: N=10; eulerN; plot(t,y); you should see the Euler approximation plotted with step number N = 10. Hint: Modify euler5.m appropriately, and change 5 to N. Obtain the Euler approximation for N = 5, 10, 20, 40, 80 and plot all of these approximations on the same graph. There is no need to plot different traces with different colors. Hint: You may want to occasionally use clear to clear the workspace of certain variables. Use hold on; to plot all approximations on the same graph. The exact solution to this differential equation is: y = 8 - 2t - 7exp(t/2). Plot this exact solution with the above Euler approximations. You should see that, with increasing N, the Euler approximations are closer to the exact solution. To quantify the difference between the Euler approximation and the exact solution, run the following code (either from the command line or by creating an m-file). z = 8 - 2*2 - 7*exp(2/2); % exact solution at t = 2 for k = 1:5 N = 5*2^(k-1); eulerN; % difference between Euler approximation and exact solution at t = 2 error(k) = y(N+1) - z; end Make sense of what the above code is doing, and display error from the command prompt. Check that the error(k+1) is approximately half of error(k). The Euler approximation improves approximately by a factor of 2 as you reduce the step size by half. The Euler method is said to be a first order method. A second order method produces an approximate solution that improves in accuracy by a factor of 2^2 = 4 as the step size is reduced by half. Likewise, in a k-th order method, the solution improves by a factor of 2^k. How can we devise a second order method? One way is to recall numerical integration. You may remember that the left endpoint rule of numerical integration only gives you first order accuracy, but the midpoint rule or trapezoidal rule of numerical integration gives you second order accuracy. The Euler method is a generalization of the left endpoint rule. If we can come up with a suitable generalization of the midpoint rule or trapezoidal rule in the context of differential equations, we should obtain a second order method. But a detailed discussion of this will have to wait until you take a course in numerical methods. This is Euler 5: euler5.m: h = 2/5; t = zeros(1,6); y = zeros(1,6); t(1) = 0; y(1) = 1; for n = 1:5 t(n+1) = t(n) + h; y(n+1) = y(n) + ((1/2)*y(n) + 2*t(n))*h; end

Sri K.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,127 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,020 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,223 solutions

*

Transcript

-
00:02 To the loan class.
00:08 Java.
00:13 Find monthly payment.
00:17 Find monthly payment.
00:26 Public double.
00:31 Get monthly payment.
00:41 Double monthly interest rate equals to equals to annual interest rate...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever