Vary the step size, h = Delta x = 0.2, 0.1 and 0.01 over 0 lessthanorequalto x l
ID: 3774766 • Letter: V
Question
Vary the step size, h = Delta x = 0.2, 0.1 and 0.01 over 0 lessthanorequalto x lessthanorequalto 2. Intel condition, y(x=0) = 1 dy/dx = yx^2 - 1.2y (b) Obtain the closed form or analytical solution of above first ODE (Due: 11/21 in class) (c) Calculate the % numerical error, E_t, in Matlab based on analytical solution. (d) Your Matlab program must be able to plot the results for (i) all the 4 numerical methods, analytical solution in one sub-plot window and (ii) % numerical ertors (in another split sub-plot window). E_t, when in = 0.2, 0 1 and 0.01 over 0 lessthanorequalto x lessthanorequalto 2. Plots windows for different h values should follow one after another with pause command and click of user and with proper label for h values in each window's title. You can split the plot window into two vertical halves.Explanation / Answer
class StringSet
{
//An instance variable of type String[]
String[] set;
//An int instance variable that indicates the number of String objects that the StringSet currently contains.
int numOfStrings;
//A no argument constructor.
public StringSet()
{
numOfStrings = 0;
set = new String[10];
}
//A mutator that adds a String newStr to the StringSet object.
void add(String newStr)
{
set[numOfStrings++] = newStr;
}
//An accessor that returns the number of String objects that have been added to this StringSet object.
int size()
{
return numOfStrings;
}
//An accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object.
int numChars()
{
int sum = 0;
for(int i = 0; i < numOfStrings; i++)
sum += set[i].length();
return sum;
}
//An accessor that returns the number of Strings in the StringSet object that have exactly len characters.
int countStrings(int len)
{
int count = 0;
for(int i = 0; i < numOfStrings; i++)
if(set[i].length() == len)
count++;
return count;
}
}
And the code for StringSetTester.java is:
import java.util.*;
class StringSetTester
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
System.out.print("How many strings will you enter? ");
int numStr = kybd.nextInt();
kybd.nextLine();
StringSet ss = new StringSet();
for(int i = 0; i < numStr; i++)
{
System.out.print("Enter string " + (i+1) + ": ");
String temp = kybd.nextLine();
ss.add(temp);
}
System.out.println("The size of the StringSet is: " + ss.size());
System.out.println("The number of characters in StringSet is: " + ss.numChars());
System.out.println("The number of strings of length 5 are: " + ss.countStrings(5));
System.out.println("The number of strings of length 7 are: " + ss.countStrings(7));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.