Public class Edo1 { private static double euler(double y, double h, double t, Derivada d) { return y + h * d.f(y, t); } public static void euler(double.

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
For(int i = 1; i
TNPL JoongJin-Cho Runge-kutta’s method of order 4.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
EC-241 Object-Oriented Programming
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.
För algoritm, se figur 6.9 i Java Gently, sidan 179.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
תרגול 12 מעקב אובייקטים 1. Our exams material : Course Syllabus : includes all the material.
Do You Understand Methods and Parameters? In this section you will be shown 25 different programs. Most of these programs have some type of error. A few,
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Nested References 2 inner reference data types Classes-Interfaces.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Object-Oriented Programming Simple Stack Implementation.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Method overloading contd class OverloadDemo { public static void main(String args[]) { Overload ob = new Overload(); int resI; double resD; // call all.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Staples are our staple Building upon our solution.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Static Members.
תרגול 3 שיטות ומערכים.
יסודות מדעי המחשב – תרגול 3
Department of Computer Science
התוכנית: using System; using System.Collections.Generic;
using System; namespace Demo01 { class Program
Interface.
Function Call Trace public class Newton {
Interfaces and an Array List
Method Mark and Lyubo.
Decision statements. - They can use logic to arrive at desired results
Functions Used to write code only once Can use parameters.
Computing Adjusted Quiz Total Score
null, true, and false are also reserved.
Stack Memory 2 (also called Call Stack)
An Introduction to Java – Part I, language basics
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
Introduction to Programming
Assignment 7 User Defined Classes Part 2
Java Lesson 36 Mr. Kalmes.
Code Animation Examples
References, Objects, and Parameter Passing
Method Overloading in JAVA
Recursive GCD Demo public class Euclid {
Default Arguments.
,. . ' ;; '.. I I tI I t : /..: /.. ' : ····t I 'h I.;.; '..'.. I ' :".:".
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Web Service.
PreAP Computer Science Review Quiz 08
Methods and Data Passing
Scope of variables class scopeofvars {
Methods and Data Passing
Philosopher Example class PhilosophersShare {
Local variables and how to recognize them
Problema: resolver un sistema de ecuaciones lineales a11x1 + a12x a1nxn = b1 a21x1 + a22x a2nxn = b an1x1.
MIS 222 – Lecture 12 10/9/2003.
Presentation transcript:

public class Edo1 { private static double euler(double y, double h, double t, Derivada d) { return y + h * d.f(y, t); } public static void euler(double t[], double y[], double y0, double t1, double t2, int ni, Derivada d) { double h = Math.abs(t2 - t1) / ni; t[0] = t1; y[0] = y0; for(int i = 0; i < ni - 1; i++) { y[i + 1] = euler(y[i], h, t[i], d); t[i + 1] = t[i] + h; } } } Para 1 ecuación

class Derivada { private double k =.27; public double f(double y, double t) { return -k * y; } } class Prueba { public static void main(String s[]) { int ni = 10; double x[] = new double[ni]; double y[] = new double[ni]; Derivada der = new Derivada(); Edo1.euler(x, y, 10, 0., 20., ni, der); for(int i = 0; i < ni; i++) { System.out.println(x[i] + " " + y[i]); } } }

private static void euler(double y1[], double h, double t, Derivadas derivadas) { double dydt[] = new double[y1.length]; derivadas.f(y1, t, dydt); for(int i = 0; i < y1.length;i++) y1[i] = y1[i] + h * dydt[i]; } private static double euler(double y1, double h, double t, Derivada derivada) { return y1 + h * derivada.f(y1, t); } Para Ne Ecuaciones

class Derivadas { public void f(double y[], double t, double dydt[]) { dydt[0] = (5 * y[1] / (y[1] +.9) -.7) * y[0]; dydt[1] = -(5 * y[1] / (y[1] +.9)) * y[0]; } } Por ejemplo para dos ecuaciones