Complex Numbers - Converting Syntax?
Mar 17, 2015Convert 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)))
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)))
I found an open-source recipe for converting numbers to words.
I modified it a bit since the requirement is only for integers until 999:
public class NumberToWordsConverter {
private String[] ones = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"};
[Code] .....
From robosoul's response at StackOverflow, I simply inserted a condition for negative integers (line 12). True enough, the code worked and I was able to trace (pen and paper method) how it is converting the 0 and positive integers to words.
However, I am a bit lost on how it is doing the conversion for negative integers. How it is successfully converting the negative?
I need to convert units accurately. Some of these units include angstroms (0.1nm) and astronomical units or light years. I can't seem to accurately perform these equations (probably mostly because of lack of a proper conversion formula). For example:
1 angstrom = 1.79985601 × 10^-14 leagues (or, 0.00000000000001799856 leagues).
To perform the conversion right now, I'm simply multiplying the angstroms by 0.00000000000001799856. However, inputting 55560000000000 (angstroms in one league) results in 0.9999999936. Why is this? Is it possible to work around it? I believe there's a term for the inability for a computer to process 1/3rd properly, but I can't remember what it's called - is that the problem?
I am using BigDecimals for all equations.
Edit: a mod can change the title if they think another is more fitting.
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]...
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.
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 RelatedI 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.
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.
Java has not structures, I must allocate whole object to one complex number?
Java has complex numbers handling, classes for complex?
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.
why we use only three dots(...) in vararg method???
View Replies View RelatedI know the first line below creates an object but the second line creates an array of cars, I'm just not sure how it does that. I can see sportsCar is one object in the array but the others are written in a different way. It seems there should a couple names there instead. Please explain the syntax in this code that's highlighted. I don't know how to make sense of it and I've read through the book where I got it where it explained creating objects.
Auto sportsCar = new Auto("Ferrari", 0, 0.0);
Auto [] cars = {new auto("BMW", 100, 15.0), sportsCar, new Auto()};
Here is the original code I found on StackOverFlow. It highlights some specific words in a JTextPane.
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;
public class ColorChangeWhileTyping extends JFrame{
private int findLastNonWordChar (String text, int index) {
while (--index >= 0) {
if (String.valueOf(text.charAt(index)).matches("W")) {
[code]....
I dont know for some reason it doesnt work correctly. The colour goes away after I press Space to write the next word.
This is what i have so far, I use BlueJay to write this:
import javax.swing.JOptionPane;
public class payroll
{
String again = y;
//
private String name;
private double rate;
private double hours;
static double gross; //gross pay
[code]....
my first problem is that it expects a ")" on this line :"if ((hours <=40)rate *1);"For the assignment itself these are the requirements:
-Create a class called payroll with private variables for rate hours and name
-Create static variables for gross pay, union dues, health coverage (hp in my case), FICA taxes, State taxes, Federal taxes, net pay, all must be initialized to 0
-default constructor that assigns default values
a function called calcPay that will do the following tasks and print it to a pay stub :
- function that checks the hours ( if hours are 40 or less pay rate, if over 40 pay 150% of the rate)
- calculates gross pay before any deductions (using user inputted hours and rate)
- deduct medical coverage and union dues from gross pay and call this adjusted gross pay (also this should have its own line on the paystub)
- A function that deducts State, federal and fica taxes from adjusted gross
- FICA - 7% for any income
-Federal - 2% for $0-$150 / 6% for 150.01 - 300 / 14% for 300.01 - 600 / 18% for 600.01 - unlimited
-State - 1% for 0-150/ 3% 150.01 - 300 / 5% 300.01 - 600/ 8% 600.01 - unlimited
- amount after all deductions is the net pay ( show this amount on its own line)
- Start a loop that asks each time if there are more employees (y/n) y should continue the program and n should end it
-dialog boxes should be created to recieve values for name, hours and rate
- if the rate is entered below $8 dollars a new box should pop up and ask for a higher value
- When there are no more employees, print out a summary of quantities stored in static variable (also had a problem with this)
- End
So I think i completed most of these objectives but am having trouble with the syntax and some of the objectives
So my only error in the entire code is on the 9th line of this code sample. It says "Syntax Error on token "new", @ expected" but @ does not belong there, as far as I can tell, since the error does not go away upon adding it.
public class Obstapacalypse implements KeyListener, ActionListener {
private static final String EXIT_ON_CLOSE = null;
private JFrame frame;
private Player player = new Player();
private JPanel contentPane;
private JButton btnStart;
[code]....
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.
I was trying to find the complete readLine() method In the online docs but all I can get hold of Is:
readLine
public String readLine()
throws IOException
Reads a line of text. A line is considered to be terminated by any one of a line feed
('
'), a carriage return ('
'),
or a carriage return followed immediately by a linefeed.
Returns:A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reachedThrows:IOException - If an I/O error occursSee Also:Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)
Is It possible to view the actual method syntax online ?
My issue is that when I run the code if I enter anything but 1, 2, or 3 the code breaks. I have spent hours trying to find the error. here is my code
import java.util.Scanner;
public class Tester {
public static void main(String[] args) {
/**
* constructor
* pre: none
* post: inherit values of other classes
*/
Car Car = new Car(); //inherits the properties of the Car class
Truck Truck = new Truck(); //inherits the properties of the Truck class
[code]....
I'm not sure why I'm getting these errors. They only begin to happen after the second if statement, and the subsequent if statements are formatted exactly the same.
The errors are marked by the comments in the code.
Java Code:
import java.util.*;
import java.io.*;
public class GazillionSongs {
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Welcome to Java Song Collection!");
System.out
.println("This program sorts and filters large databases of popular songs.");
[Code] .....
My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
package Homework2;
import java.util.Scanner;
public class Homework2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to the Triangle Program.");
[Code] ....
In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:
<sql:query dataSource="${user}" var="result">
SELECT * from users where email = ${sessionScope.email};
</sql:query>
It doesn't work.
How do I insert space between my int and the statement?
My out put it is: A heptagon has7 sides .
what I want is: A heptagon has 7 sides .
public class Geomerty {
public static void main(String[] args) {
int sides = 7;
System.out.println( "A heptagon has" + sides + " sides ." );
}
}
I have a problem with my code. It gives me the error I put as title:
backgroundA.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
if (j < 2){
int randomInt1 = random1.nextInt(Deck.length());
int drawableIDA = Deck.getResourceId(randomInt1, -1);
[Code] ....
This error is in the first line and I have also one in the last, where eclipse looking for a @ (O.o). Also I will insert the variable choice1.
final Button choice1 = (Button) findViewById(R.id.A);
The following gives the error: E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E:
An exception was thrown by one of the service methods of the servlet [/Sampling/SamplingInspectionItemFaxFormV6.jsp] in application [QMSWeb AppEAR]. Exception created : [javax.el.MethodNotFoundException: java.lang.NoSuchMethodException: java.util.ArrayList.get(java.lang.Long)
The bean property is an ArrayList<String> with two elements, '100','true'
<c:choose>
<c:when test="${sidocObj.samplesizedata.get(1) == 'true'}">
<img class="modified15" src="/QMSWebApp/Images/check[2].jpg"><SPAN class="scaledLimeSpan1">Sample Size has been Overriden by SQE!</SPAN><BR>
</c:when>
</c:choose>
I have a problem with my code. It gives me the error I put as title:
backgroundA.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
if (j < 2){
[Code]...
This error is in the first line and I have also one in the last, where eclipse looking for a @ (O.o). Also I will insert the variable choice1.
final Button choice1 = (Button) findViewById(R.id.A);
I am following this article : [URL] ....
And I have created 4 different types of Interfaces and Classes
Interface:-Flyer,Mythical
Class:-Horse,Pegasys.
But on Interface
I am getting error on line
default public String identifyMyself()
"Syntax error on token "default" delete this token"
Here is code for all 4 interfaces and classes
public class Horse {
public String identifyMyself() {
return "I am a horse.";
}
}
public interface Flyer {
default public String identifyMyself() {
[Code] ....