Complex Number Calculations

Jan 25, 2014

A complex number is defined as z=a+i*b, where a is the real part, and b is the imaginary part. In other words, in order to define a complex number, we need the two floating numbers a and b. Write methods that perform for each of the following operations with complex numbers z1 = a1 + i*b1, and z2 = a2 + i*b2:

Addition: z1 + z2=(a1+a2) + i*(b1+b2)
Subtraction: z1 - z2=(a1-a2) + i*(b1-b2)
Multiplication: z1*z2 = (a1*a2 - b1*b2) + i*(a1*b2 + b1*a2)
Division: z1/z2 = (a1*a2 +b1*b2)/(a2^2 + b2^2) + i*(b1*a2 - a1*b2)/(a2^2 + b2^2)

Create a test program that asks for the real and imaginary parts of two complex numbers from the user, and displays the results of the four operations, writing the formula as shown above, and replacing the a1, a2, b1 and b2 with the numbers entered by the user.The professor used the incorrect complex number equations and has notified the students of his error. I have run into a few problems thus far.

1. I'm not sure how to use floating numbers with the Math.pow(double, double) function, since its requires doubles!? So instead of using floating numbers, I've knowingly switched them all to double in order to see if the code itself is working properly for the purposes of this forum. Is there a way that I can modify this function so that it will work for floating numbers?

2. Regarding the division method, an error stating that c and d have not been initialized and I'm not sure how to change it because the other calculation methods work fine. Why do I need to initialize c and d in the division method and not the others?

3. Am I on the right path? I have surfed the web to see how others completed the program and they all appear very different than mine...

package program5;
import java.util.Scanner;
public class Program5 {
  static double a, b, c, d;
static double i = Math.pow(-1,1/2);
 
[code]...

View Replies


ADVERTISEMENT

Java - Allocate Whole Object To One Complex Number

Jul 6, 2014

Java has not structures, I must allocate whole object to one complex number?

Java has complex numbers handling, classes for complex?

View Replies View Related

Adding Into A Complex Array?

May 26, 2015

I have a main class:

Java Code:

public class Main {
public static void main(String[] args) {
Player[] playerList = new Player[] {new Player("Daniel", 3, 3, 2, 1, 1, 3),new Player ("Player2", 2, 4, 1, 6, 3, 2)};
System.out.println(Player.getPlayer());
}
} mh_sh_highlight_all('java');

[code]....

and whenever I run it, it prints out the last player, so I was wondering how to identify them separately, but still use the array, as (I believe) it is the most efficient way.

View Replies View Related

Complex Formatting Within A Text Field

Apr 30, 2015

I'm trying to figure out a good way to allow my users to have some formatting options within a text box in my application. Ultimately, they need to be able to have text that is alternating between two separate fonts, and ideally could have both italicized and bolded words as well.

View Replies View Related

Complex Numbers - Converting Syntax?

Mar 17, 2015

Convert to following sysntax (from Matlab) having complex nos.

real((413000*atan((T^(1/2)*((4130000*V*1i)/(139*T^(1/2)) + (413000*1i)/T^(1/2)))/413000)*1i)/(139*T^(1/2)))

View Replies View Related

Complex Math Functions With A Simple Web Page?

Feb 4, 2015

I am a 3rd year electrical engineer and I am working on a project on solar cell design in the developing world.For my project I am looking to create a very simple web page which can be used by people in the developing world to determine whether a photo voltaic system is suitable to their needs.

For this I want to have simple boxes where a user can input numbers and I used complex calculations to return values (a lot of trigonometric functions etc.), the values then should have the opportunity to be altered to the users digression. This will create a solar model.

For the load aspect of it I am looking to have drop down boxes for a number of components which the user can select and will have a numerical value in Watts which will sum to give total load on system. Ideally I would like to show this graphically in a pie chart showing how much energy each component is taking to give the option to remove.

I am also creating a statistical model which determines the likelihood of having no sunlight on a given day which looks at the solar output, battery capacity and load on the system and will return reliability of the system - this has not been completed but should be shortly.

Aim is to keep web page as simple as possible as unskilled computer users may want to use it.

View Replies View Related

Deleting Complex Object In Java List

Sep 3, 2014

I am following those three tutorials and I have completed it with success.

( [URL] .... )
( [URL] .... )
( [URL] .... )

But then, as author haven't implemented removeCountries method I tried to create it. What I did initially was to just add to class Countries this method:

public boolean removeCountry(Country country) {
return countries.remove(country);
}

But although compiler wasn't complaining it didn't work. Actually it worked last night (before reboot) but not today. Must be some SOAP iterator/binding thing or whatever. Or I thought that it worked but in fact it didn't.

Here are original classes:

//-------------------------------
public class Country {
String CountryId;
String CountryName;
public Country() {
super();

[Code] ....

I would like to avoid my own iterator as JDeveloper can generate automatically iterators for webservices, but if I can't get it that way, what would be better way to write above mentioned iterator in removeCountry method?

Is there any way to remove object directly with something like this:

co.countries.remove(o);
co.removeCountry(country)

using method

// This left unused
public boolean removeCountry(Country country) {
return countries.remove(country);
}

from class Countries?

Parameters should be set by web service iterator.

View Replies View Related

JavaFX 2.0 :: Synchronize Model Representing Complex UI Composite With FlowPane Backing List

Aug 26, 2014

What is the best way to synchronize a Model representing a complex UI composite w/ a FlowPane's backing list?
 
Currently I have a change listener on the Model.  Upon an add I create a new UI composite and manually add it to the FlowPane's backing list via flowPane.getChildren().add().  Similarly if there is a remove, I iterate over the FlowPane's children, grab the right Node, and remove it.  Similarly, if there is a modification detected, I iterate over the FlowPane's children, grab the right Node, remove it, recreate the UI composite, and re-add it to the list.  I also need the list to be sorted, so I implemented a UIComposite comparator and call FXCollections.sort() on the FlowPane's backing list.  I feel like that is hacky, but it works.  It would be cool if I could maintain sort order in my model somehow and have that automatically propogated to the FlowPane's list.
 
I am correct in assuming that there is no way to have a complex binding in between an ObservableList<CompositeViewModel> and the FlowPane's backing list (ObservableList<T>)? 

Some kind of translator that could create a new UIComposite whenever there is a new CompositeViewModel added to the Model list.

View Replies View Related

Calculations Within A Set Method

Feb 13, 2015

I am almost done with the assignment, but I am having an issue with this step: "Create a field to hold the gallery commission. This field cannot be set from outside the class. it is computed as 20% of the price, and should be set whenever the price is set. Put the code to calculate and set the commission in the setPrice() method"

import java.util.Scanner;
public class PaintingHarness
{
public static void main(String[] args)
{
// put code here
// Created object so we can take input from the Scanner
Scanner input = new Scanner(System.in);
Painting myPainting = new Painting();

[code]....

View Replies View Related

Accessing Data For Calculations?

Feb 18, 2015

I've created a method to calculate the ratio of one vowel to another, but I was hoping to get some feedback on another way I could approach the problem. The first bit of code is to find the vowels and assign them to an array ( for me, it seemed the easier thing to do in order to easily access the data). In the other bit of code, I have a method with two arguments (the vowels) to calculate the ratio.

public void findVowels(StringBuilder message, String delimiter) {
subString = message.toString().toLowerCase().split(delimiter);
vowelCounter = new int[5][subString.length];
// Remove all whitespace
for (int index = 0; index < subString.length; index++) {
subString[index] = subString[index].replaceAll("s", "");

[code]....

View Replies View Related

Calculations On Text Box Inputs

Mar 7, 2014

I have made a simple form, it consists of 3 text box's textbox1, textbox2 and textbox3 as well as 1 button button1. What I want to be able to do is put numbers into textbox 1 and 2 and then show the multiplication of these numbers in textbox 3 when the button is pressed and I was wondering what is the standard way of reading these numbers from the text box and allowing us to do the conversion obviously in the textbox its a string and we need to convert to an int or double or whatever to be able to perform calculations on them then convert it back into a string to display in text box 3?

View Replies View Related

Program Returns 0 For All Calculations

May 28, 2014

this program works but returns zero for all the calculations. I checked everything there is no error but I dont know why is returning 0.

package mshproject3;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public class HayloFactoryController {
public static void main(String[] args) {
String firstName = "";
String lastName = "";
String phoneNumber = "";
int aNbrOfVehicles = 0;
int aNbrOfFuelTanks = 0;
HayloFactory factory;

[code]....

View Replies View Related

Array In Class Calculations Out Of Bounds?

Mar 26, 2014

It seems that all of my arrays in the class Calculations are out of bounds, and I do not seem to know why.

Java Code:

/**
public class DataAnalyzer
{
public static void main (String[] args) {
//This creates an instance of ReadFiles
ReadFiles aReadFiles = new ReadFiles();
Calculations aCalculations = new Calculations();

[code]....

View Replies View Related

What Code To Manipulate Strings To Do Calculations

Dec 4, 2014

I have some data files that take this form:

D14
J3
N1
a26

[code]...

I also have this code that takes the file, goes through each line using a loop and counts the total of all the integers on each line, it also then loops and takes each integer on each line and divides it by the total calculated in the previous loop but I don't know what code to manipulate the strings to do these calculations. After these calculations I want to write the updated values to the text file I originally took the data in from. So as an example the total I already for this file to be '232' so the first line would be D 0.06 because 14/232 = 0.06034482758 and rounded to 2 decimal points is 0.06.

import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Normalise {
private static Scanner scanner;
//private static PrintWriter out;

[code]....

View Replies View Related

Using Two Dimensional Arrays To Make Calculations

May 10, 2014

I am having problems figuring out how to make calculations using a two dimensional array. The problem is finding the distance of a projectile given the launch velocity and angle. The equation is x = v^2*sin(2theta)/g. I understand how to implement this equation using the toRadians() and Sin() methods. What I don't understand is how to calculate the distance values with a multi dimensional array.

double [][] data = { {20, 15},
{50, 35},
{80, 45},
{100, 65},
{150, 85},
{10, 50},
{110, 8}};

My array has the velocities on the left and angles on the right. I tried using nested loops but I don't know how to access the two pieces of data at a time which I need.

View Replies View Related

RMI With Doing Calculations Across A Server / Client Platform

Apr 6, 2014

It's an RMI program that has to be able to return the mean, mode and median of a set of numbers.It's composed of 4 classes; a client, an implementation class (with the math), an Interface, and a server class.

import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.*;
 
[code]....

View Replies View Related

How To Perform Calculations Using Stacks Java

Nov 23, 2014

I am doing a calculator using stacks but when i try to calculate I getting the wrong data example stack contains 8 and user enter -3 stack should change to 5.

package comp10152.lab5;
import java.util.Scanner;
import java.util.Stack;

[Code].....

View Replies View Related

Lottery Odds Program - Using For And While Loops With Calculations

Oct 13, 2014

/**
* In this program, use for and while loops with calculations to get the lottery odds.
*/
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String []args)

[Code] .....

I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.

View Replies View Related

2D Array Computation - Performing Certain Matrix Calculations

Apr 22, 2015

I've created several methods in another class to perform certain matrix calculations. Do I need to have mutator method in this calculation class to define the column length of the matrix object? I understand why the following code is not working, but I was hoping to get a quick and easy workaround. I'm not sure how to initialize the size of the column for newMatrix within the method.

public int [][] sum(int matrixOne[][], int matrixTwo[][]) {
int sumMatrix [][] = new int[matrixOne.length]["WHAT TO PUT HERE"];
for (int i = 0; i < matrixOne.length; i++) {
for (int j = 0; j < matrixOne[i].length; j++) {
sumMatrix[i][j] = matrixOne[i][j] + matrixTwo[i][j];
System.out.println("matrixSum" + sumMatrix[i][j]);
}
}
return sumMatrix;
}

Then I will use this method to print the new matrix:

public void printMatrix(int newMatrix [][]) {
for (int i = 0; i < newMatrix.length; i++) {
for (int j = 0; j < newMatrix[i].length; j++) {
System.out.print(newMatrix[i][j] + " ");
}
System.out.println("");
}
}

Is all of this overkill and should I just define all the methods within the same class to avoid these issues?

View Replies View Related

Generate Conditions To Perform Calculations On Whole Numbers?

Dec 12, 2014

I have to ask the user to enter 4 whole numbers, and then the program will calculate:

> x numbers are positive and even
> x numbers are positive and odd
> x numbers are negative and even
> x numbers are negative and odd

but I have trouble with the conditions. How do I form the conditions to calculate this? My professor said I can do this with only four IFs (or ELSE IF). This is what I did:

import java.util.Scanner;
public class Calc{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
 
int pe = 0, po = 0, ne = 0, no = 0;
/* four variables for each result
pe - positive even
po - positive odd
ne - negative even
no - negative odd

[Code[ ....

View Replies View Related

Adding Inputs To Table With Columns And Perform Calculations Later

Nov 22, 2014

I am trying to put together a small application in my spare time. Nothing major, but one thing I want it to do is accept a few inputs, and take those and add them to a table with columns for use later (printing, calculations, etc). I was originally looking at something like Jtable, but that looks just like an excel spreadsheet done Java, so not what I'm looking for.

I'm looking for something that's read-only, where I can insert data from input fields, and then perform calculations with the column data later.

View Replies View Related

Grade Average Program - Hit Button Reseved For Calculations

Nov 23, 2014

I have written a simple grade average program. This is my code:

package programs;
 import java.util.Scanner;
 public class GradeAverage {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
int number;
int counter = 0;
int grade;
 
[Code] ....

Now the program is working just fine but what I don't like about it is the fact that you have to enter the number of grades before entering the grades. What I would prefer is to write your grades, hit some button that is reserved for calculating the average and then get the output.

View Replies View Related

Simple Data Classes - Serialize More Complex Data Structure

Oct 6, 2014

I have written several simple data classes that I serialized manually by converting to text. At this point I need to serialize a more complex data structure. which will include lists of the simpler elements. Can serialize store and reconstitute this type of structure automatically or do I need to do this one manually as well? Consider the pseudocode below for a clarification of my question;

Java Code:

Class Hops{
String Name;
float Alpha Acid;
float Beta Acid;
};

Class Malt{
String Name;
float extract;
};

Class Recipie{
String Name;
CList HopList;
CList MaltList;
};

CList RecipieList; mh_sh_highlight_all('java');

I read the article on Serialization presented at tutorial point, but the example only showed a simple class, not lists of class members. What I want to do is serialize RecipieList, which consists of a CList of Recipies, which in turn consist of CLists of various ingredients.

View Replies View Related

Calculations / Conversions - Calculate Correct Amount Of Change Due To A Customer

Sep 12, 2014

Here are the instructions to my assignment:

A shopkeeper in Diagon Alley needs you to write a program that will calculate the correct amount of change due to a customer. (In Diagon Alley they use three coins with different values, given below).

1. Prompt the user to input the amount of sale in Galleons, Sickles, and Knuts.

2. Prompt the user to input the amount of money given by the customer in Galleons, Sickles, and Knuts.

3. Create constants that represent:

a. 1 Galleon = 17 Sickles

b. 1 Sickle = 29 Knuts

4. Perform the necessary calculations and conversions to compute the correct change in the least number of coins.

5. create a formatted receipt recording the entire transaction.

Here are what is steps 1 and 2 and 5 but problem with are 3 and 4. I need to create the constants and use proper conversions to give the right amount of change back.

Java Code:

import java.util.Scanner;
public class OperatorFormatting {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Flourish and Blotts");

[Code] ....

Basically, on steps 3 and 4 which are creating the constants and using the to make the proper conversions to give the customer the proper amount of change Due.

View Replies View Related

Simple Program Giving Negative Result For Amount Of Calculations Done

Mar 5, 2014

Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).

Java Code:

class Benchmark {
public static void main(String[] args) {
long endTime = System.currentTimeMillis() + 60000;
int count = 0;
for (int i = 0; System.currentTimeMillis() < endTime; i++) {
double x = Math.sqrt(System.currentTimeMillis());
count = i;
}
System.out.print(count + " calculations per minute");
}
} mh_sh_highlight_all('java');

I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?

View Replies View Related

PageRank In Naive Manner With Graph Nodes As Pages And Subsequent Calculations

Apr 15, 2014

Trying to implement PageRank in a naive manner with graph nodes as pages and subsequent calculations. Correcting the code.

import java.util.*;
import java.io.*;
class PageRank {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no.of pages");
int n=sc.nextInt();

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved