P2P / CE Uebungen + Folien
This commit is contained in:
parent
3b657d2847
commit
4a9265e76a
BIN
ws2012/CE/uebungen/5/EiCE_Uebung05.pdf
Normal file
BIN
ws2012/CE/uebungen/5/EiCE_Uebung05.pdf
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/6/A1_Lukas.jpg
Normal file
BIN
ws2012/CE/uebungen/6/A1_Lukas.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 MiB |
BIN
ws2012/CE/uebungen/6/EiCE_Uebung06.pdf
Normal file
BIN
ws2012/CE/uebungen/6/EiCE_Uebung06.pdf
Normal file
Binary file not shown.
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>DEVS2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,12 +0,0 @@
|
||||
#Thu Oct 11 22:30:59 CEST 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,117 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/* This class implements a time dependent discrete event simulation */
|
||||
abstract public class DEVS {
|
||||
|
||||
// GENERAL
|
||||
protected PriorityQueue<DiscreteEvent> queue;
|
||||
private double time;
|
||||
private double maxTime;
|
||||
|
||||
// CONSTRUCTOR
|
||||
public DEVS(){
|
||||
queue = new PriorityQueue<DiscreteEvent>(2);
|
||||
time = 0.0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected class StopEvent extends DiscreteEvent{
|
||||
StopEvent(double t) {
|
||||
super(t,'X');
|
||||
}
|
||||
}
|
||||
|
||||
// USER-DEFINED FUNCTIONS
|
||||
/** This routine may be implemented */
|
||||
public void initialize() {
|
||||
queue.add(new StopEvent(maxTime));
|
||||
}
|
||||
|
||||
/** This routine must be implemented */
|
||||
abstract public void eventRoutine(DiscreteEvent ev);
|
||||
|
||||
/** This routine may be implemented */
|
||||
public void statistics() {}
|
||||
|
||||
|
||||
|
||||
// GENERAL FUNCTIONS
|
||||
/** getter time */
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/** setter time */
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/** getter max time */
|
||||
public double getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/** setter max time */
|
||||
public void setMaxTime(double time) {
|
||||
this.maxTime = time;
|
||||
}
|
||||
|
||||
|
||||
/** Simulation stops if time limit has been reached*/
|
||||
public boolean stopCondition() {
|
||||
return getTime() > getMaxTime();
|
||||
}
|
||||
|
||||
/** Perform simulation run (event loop) */
|
||||
public void simulate(){
|
||||
|
||||
while (true){
|
||||
|
||||
// get event
|
||||
DiscreteEvent ev = queue.poll();
|
||||
|
||||
// abort, if queue is empty
|
||||
if (ev==null) {
|
||||
System.out.println("Queue is empty!");
|
||||
break;
|
||||
}
|
||||
|
||||
// update time and treat event
|
||||
time = ev.getTime();
|
||||
eventRoutine(ev);
|
||||
|
||||
// print queue status
|
||||
System.out.print("{");
|
||||
|
||||
for (Iterator<DiscreteEvent> it = queue.iterator(); it.hasNext();)
|
||||
{
|
||||
System.out.print(it.next()+", ");
|
||||
}
|
||||
System.out.println("}");
|
||||
|
||||
// check for stop condition
|
||||
if (ev instanceof StopEvent)
|
||||
{
|
||||
System.out.println("Terminating");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DEVSMain {
|
||||
|
||||
/** execute program */
|
||||
public static void main(String args[]){
|
||||
|
||||
// create random number generator
|
||||
RandomNumberGenerator randA;
|
||||
RandomNumberGenerator randD;
|
||||
double maxtime;
|
||||
|
||||
// ALTERNATIVE 1: results from exercise 1
|
||||
// TODO: VAlidierung in Aufgabenteil b)
|
||||
randA = new MyExponential();
|
||||
randD = new MyNormalDist();
|
||||
maxtime = 100.0;
|
||||
|
||||
|
||||
// ALTERNATIVE 2: 'real' random numbers
|
||||
// TODO: Experimente in Aufgabenteil d)
|
||||
/* Random r = new Random(47);
|
||||
|
||||
|
||||
randA = new ExponentialDistributionWrapper(r, 5.0);
|
||||
randD = new ExponentialDistributionWrapper(r, 6.0);
|
||||
//randD= new NormalDistributionWrapper(r, 6.0, 2.0);
|
||||
maxtime = 20000;
|
||||
*/
|
||||
|
||||
DEVS sim = new QueueDEVS(randA, randD);
|
||||
|
||||
sim.setMaxTime(maxtime);
|
||||
sim.initialize();
|
||||
sim.simulate();
|
||||
|
||||
sim.statistics();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
import java.lang.Double;
|
||||
|
||||
public class DiscreteEvent implements Comparable<DiscreteEvent>{
|
||||
|
||||
private double time;
|
||||
private char type;
|
||||
|
||||
|
||||
DiscreteEvent(double t, char c) {time=t; type=c;}
|
||||
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public char getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(char type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
return "Event<"+type+", "+time+">";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int compareTo(DiscreteEvent e) {
|
||||
return new Double(time).compareTo(e.getTime());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/** Generiert Werte einer Exponentialverteilung */
|
||||
public class ExponentialDistributionWrapper implements RandomNumberGenerator {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private double lambda;
|
||||
private Random r;
|
||||
private boolean doInteger;
|
||||
|
||||
public ExponentialDistributionWrapper(Random r){
|
||||
this (r, 1.0);
|
||||
}
|
||||
|
||||
public ExponentialDistributionWrapper(Random r, double lambda){
|
||||
this.doInteger=false;
|
||||
this.r = r;
|
||||
this.lambda=lambda;
|
||||
}
|
||||
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double x = r.nextDouble();
|
||||
if (doInteger) return (double) Math.round(-Math.log(1.0-x)/lambda);
|
||||
return -Math.log(1.0-x)/lambda;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
public class MyExponential implements RandomNumberGenerator
|
||||
|
||||
{
|
||||
MyExponential() {i=0;}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double val=data[i];
|
||||
i=(i+1)%data.length;
|
||||
return val;
|
||||
};
|
||||
|
||||
private int i;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static double data[] =
|
||||
//{0.57, 2.73, 1.36, 0.72, 0.23, 0.08, 1.21, 0.35, 2.81, 0.19, 0.88};
|
||||
{8.76, 16.82, 15.40, 26.72,3.46,27.06,23.52,8.06,0.71,42.03,56.27};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
package edu.eice2012;
|
||||
|
||||
public class MyNormalDist implements RandomNumberGenerator
|
||||
|
||||
{
|
||||
MyNormalDist() {i=0;}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double val=data[i];
|
||||
i=(i+1)%data.length;
|
||||
return val;
|
||||
};
|
||||
|
||||
private int i;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static double data[] =
|
||||
//{1.89, 2.02, 2.56, 3.84, 2.00, 2.28, 3.32, 3.56, 2.97, 2.67, 2.70};
|
||||
{25.30, 20.11, 13.25, 10.68, 16.85, 19.22, 23.96, 28.30, 24.55, 22.70, 17.14};
|
||||
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package edu.eice2012;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/** Generiert Werte einer Normalverteilung */
|
||||
public class NormalDistributionWrapper implements RandomNumberGenerator{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private double mu;
|
||||
private double sigma;
|
||||
private Random r;
|
||||
private boolean doInteger; // returning integers or doubles?
|
||||
|
||||
|
||||
public NormalDistributionWrapper(Random r){
|
||||
this(r, 0.0, 1.0);
|
||||
}
|
||||
|
||||
public NormalDistributionWrapper(Random r, double mu, double sigma){
|
||||
this.r = r;
|
||||
this.mu=mu;
|
||||
this.sigma=sigma;
|
||||
this.doInteger=false;
|
||||
}
|
||||
|
||||
public double nextDoubleValue(){
|
||||
double x = r.nextGaussian();
|
||||
if (doInteger) return (double) Math.round( mu +x*sigma);
|
||||
return mu +x*sigma;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,277 +0,0 @@
|
||||
/**
|
||||
Vorlesung: Einfuehrung in Computational Engineering
|
||||
@author Arne Naegel
|
||||
@date Oktober 2012
|
||||
*/
|
||||
|
||||
package edu.eice2012;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
public class QueueDEVS extends DEVS {
|
||||
|
||||
// problem specific variables
|
||||
private int server; // current machine state (0=idle)
|
||||
private int buffer; // current buffer length
|
||||
private int maxServers;
|
||||
|
||||
// random number generators
|
||||
private RandomNumberGenerator randA;
|
||||
private RandomNumberGenerator randD;
|
||||
|
||||
// statistics (per event)
|
||||
private Vector<Double> eventTimes; // time stamp when event is triggered
|
||||
private Vector<Character> eventTypes; // type of event
|
||||
private Vector<Double> serverList; // #items processed by server(s)
|
||||
private Vector<Double> bufferList; // #items in buffer
|
||||
private Vector<Double> loadList; // #items in system
|
||||
|
||||
|
||||
|
||||
/** Constructor */
|
||||
public QueueDEVS(RandomNumberGenerator randA, RandomNumberGenerator randD)
|
||||
{
|
||||
// attributes
|
||||
buffer = 0;
|
||||
server = 0;
|
||||
maxServers = 1;
|
||||
|
||||
// random numbers
|
||||
this.randA = randA;
|
||||
this.randD = randD;
|
||||
|
||||
|
||||
// statistics (per event)
|
||||
eventTimes = new Vector<Double>();
|
||||
eventTypes = new Vector<Character>();
|
||||
bufferList = new Vector<Double>();
|
||||
serverList = new Vector<Double>();
|
||||
loadList = new Vector<Double>();
|
||||
|
||||
// first entries
|
||||
eventTimes.add(0.0);
|
||||
eventTypes.add('I');
|
||||
bufferList.add(0.0);
|
||||
serverList.add(0.0);
|
||||
loadList.add(0.0);
|
||||
}
|
||||
|
||||
public void setRandomArrival(RandomNumberGenerator rand)
|
||||
{
|
||||
this.randA = rand;
|
||||
}
|
||||
|
||||
public void setRandomDeparture(RandomNumberGenerator rand)
|
||||
{
|
||||
this.randD = rand;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** status for server */
|
||||
public boolean allBusy()
|
||||
{
|
||||
return (server == maxServers);
|
||||
}
|
||||
|
||||
/** status for server */
|
||||
public boolean isIdle()
|
||||
{
|
||||
return (server==0);
|
||||
}
|
||||
|
||||
|
||||
public int getServerState() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
super.initialize();
|
||||
server = 0;
|
||||
buffer = 0;
|
||||
queue.add(new DiscreteEvent(0.5, 'A'));
|
||||
|
||||
/*
|
||||
* ALTERNATIVE: first arrival is random
|
||||
double offset = randA.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent((offset), 'A'));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/** called for every event */
|
||||
public void eventRoutine(DiscreteEvent e)
|
||||
{
|
||||
|
||||
char type = e.getType();
|
||||
switch (type)
|
||||
{
|
||||
case 'A': arrivalRoutine(e); break;
|
||||
case 'D': departureRoutine(e); break;
|
||||
|
||||
default: System.out.println("Unknown event type -> Aborting!!!");
|
||||
};
|
||||
|
||||
|
||||
// print stats
|
||||
System.out.println("Event: "+e.getTime() + "|"+type+ "|"+ buffer+ "|"+ getServerState());
|
||||
|
||||
// record event statistics (example!)
|
||||
eventTimes.add(e.getTime()); // time stamp
|
||||
eventTypes.add(e.getType()); // type (A/D/X)
|
||||
int serverState = getServerState();
|
||||
serverList.add((double) serverState); // server state
|
||||
bufferList.add((double) buffer); // buffer state
|
||||
|
||||
int nItems = buffer + serverState;
|
||||
loadList.add((double) nItems); // system load
|
||||
};
|
||||
|
||||
/** TODO: called upon arrival */
|
||||
protected void arrivalRoutine (DiscreteEvent e)
|
||||
{
|
||||
|
||||
//System.out.println("arrivalRoutine muss implementiert werden!");
|
||||
|
||||
double offset1 = randA.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent((getTime()+offset1), 'A'));
|
||||
|
||||
if(allBusy()){
|
||||
buffer++;
|
||||
}else{
|
||||
server++;
|
||||
double offset2 = randD.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent(getTime()+offset2, 'D'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** TODO: called upon departure */
|
||||
protected void departureRoutine (DiscreteEvent e)
|
||||
{
|
||||
//System.out.println("departureRoutine muss implementiert werden!");
|
||||
|
||||
if(buffer == 0){
|
||||
server = 0;
|
||||
}else{
|
||||
buffer--;
|
||||
double offset=randD.nextDoubleValue();
|
||||
queue.add(new DiscreteEvent(getTime()+offset, 'D'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** aux: compute \sum v_i */
|
||||
static protected double firstMoments(AbstractList<Double> values){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1;
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
val+=values.get(i);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i * (t_{i+1}- t_{i})*/
|
||||
static protected double firstMoments(AbstractList<Double> values, AbstractList<Double> weights){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
double dt = weights.get(i+1)-weights.get(i);
|
||||
val+=values.get(i)*dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i*v_i */
|
||||
static protected double secondMoments(AbstractList<Double> values){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
val+=values.get(i)*values.get(i);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** aux: compute \sum v_i * v_i * (t_{i+1}- t_{i})*/
|
||||
static protected double secondMoments(AbstractList<Double> values, AbstractList<Double> weights){
|
||||
double val=0.0;
|
||||
int numEvents = values.size()-1; // skip final STOP event!
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
double dt = weights.get(i+1)-weights.get(i);
|
||||
val+=values.get(i)*values.get(i)*dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** TODO:
|
||||
* aux: computes aggregated times T_k per load k
|
||||
* Hint: should be implemented analogously to firstMoments(AbstractList<Double>, AbstractList<Double>)
|
||||
* */
|
||||
static protected double[] aggregateTimesPerLoad(AbstractList<Double> times, AbstractList<Double> loads)
|
||||
{
|
||||
|
||||
int numEvents = loads.size()-1; // skip final STOP event!
|
||||
|
||||
// a) find maximum load
|
||||
int maxLoad = 0;
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
int load = (int) Math.round(loads.get(i));
|
||||
if (load > maxLoad) maxLoad = load;
|
||||
}
|
||||
|
||||
// b) compute sum of values and assign
|
||||
double val[] = new double[maxLoad+1];
|
||||
for (int i=0; i<numEvents; ++i)
|
||||
{
|
||||
int load = (int) Math.round(loads.get(i));
|
||||
double dt = times.get(i+1)-times.get(i);
|
||||
val[load] += dt;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void statistics()
|
||||
{
|
||||
|
||||
double time = getMaxTime();
|
||||
|
||||
|
||||
// example: statistics for system load
|
||||
double loadMoment1 = firstMoments(loadList, eventTimes);
|
||||
double loadMoment2 = secondMoments(loadList, eventTimes);
|
||||
double meanLoad= loadMoment1/time;
|
||||
double loadVar = (loadMoment2/time - (meanLoad)*(meanLoad));
|
||||
System.out.println("Mean system load: "+ meanLoad+" +/- "+Math.sqrt(loadVar));
|
||||
|
||||
// TODO: implement server usage
|
||||
System.out.println("Mean server usage: ??? +/- ???");
|
||||
|
||||
// times per system load
|
||||
double timeDist[] = aggregateTimesPerLoad(eventTimes, loadList);
|
||||
for (int k=0; k<timeDist.length; k++)
|
||||
{
|
||||
System.out.println("p["+k+"]="+timeDist[k]/time);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package edu.eice2012;
|
||||
|
||||
/** Objects implementing this class generate a stream of numbers */
|
||||
public interface RandomNumberGenerator {
|
||||
|
||||
public double nextDoubleValue();
|
||||
}
|
||||
BIN
ws2012/CE/uebungen/P1/DK64_DW09_MS30.zip
Normal file
BIN
ws2012/CE/uebungen/P1/DK64_DW09_MS30.zip
Normal file
Binary file not shown.
BIN
ws2012/CE/uebungen/P2/DK64_DW09_MS30.zip
Normal file
BIN
ws2012/CE/uebungen/P2/DK64_DW09_MS30.zip
Normal file
Binary file not shown.
27
ws2012/CE/uebungen/P2/P2Matlab/approxpi.m
Normal file
27
ws2012/CE/uebungen/P2/P2Matlab/approxpi.m
Normal file
@ -0,0 +1,27 @@
|
||||
function [ p ] = approxpi(n, type)
|
||||
%APPROXPI Approximates PI based on edge lengths e
|
||||
|
||||
|
||||
%vektor p:
|
||||
p = zeros(1, n);
|
||||
|
||||
%vektor edges:
|
||||
edge = zeros(1, n);
|
||||
edge(1) = 1;
|
||||
|
||||
for i=1:1:n
|
||||
switch type
|
||||
case 1
|
||||
%Behandlung für ersten Fall
|
||||
edge(i+1) = sqrt(2 - sqrt(4-edge(i)^2));
|
||||
case 2
|
||||
%Behandlung für zweiten Fall
|
||||
edge(i+1) = edge(i) / sqrt(2 + sqrt(4-edge(i)^2));
|
||||
otherwise
|
||||
disp('Wrong type!');
|
||||
end
|
||||
p(i) = 3*2^(i-1)*edge(i);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
19
ws2012/CE/uebungen/P2/P2Matlab/findeps.m
Normal file
19
ws2012/CE/uebungen/P2/P2Matlab/findeps.m
Normal file
@ -0,0 +1,19 @@
|
||||
function [eps] = findeps()
|
||||
%FINDEPS Findet die kleinste Zahl eps>0, so dass 1+eps!= 1
|
||||
|
||||
|
||||
eps = 1;
|
||||
n = 1;
|
||||
while (1.0 + eps) > 1.0
|
||||
n = n + 1; %n erhöhen
|
||||
eps = 2^(-n); %eps neu zuweisen
|
||||
end
|
||||
|
||||
%einen Schritt der while-Schleife ""rückgängig"" machen, um das letzte eps zu
|
||||
%berechnen, so dass gerade noch gilt (1.0 + eps) > 1.0
|
||||
n = n - 1;
|
||||
eps = 2^(-n);
|
||||
|
||||
|
||||
end
|
||||
|
||||
121
ws2012/CE/uebungen/P2/P2Matlab/loesung.txt
Normal file
121
ws2012/CE/uebungen/P2/P2Matlab/loesung.txt
Normal file
@ -0,0 +1,121 @@
|
||||
Gruppe:
|
||||
- Michael Scholz (Matr.# 1576630)
|
||||
- David Kaufmann (Matr.# 1481864)
|
||||
- Dennis Werner (Matr.# 1513509)
|
||||
|
||||
|
||||
Ausgabe der main-Funktion in Matlab:
|
||||
|
||||
|
||||
1. Aufruf von main(1) liefert:
|
||||
==============================
|
||||
|
||||
>> main(1)
|
||||
|
||||
e =
|
||||
|
||||
2.2204e-16
|
||||
|
||||
|
||||
p =
|
||||
|
||||
Columns 1 through 4
|
||||
|
||||
3.0000e+00 3.1058e+00 3.1326e+00 3.1394e+00
|
||||
|
||||
Columns 5 through 8
|
||||
|
||||
3.1410e+00 3.1415e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 9 through 12
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 13 through 16
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 17 through 20
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 21 through 24
|
||||
|
||||
3.1417e+00 3.1417e+00 3.1431e+00 3.1598e+00
|
||||
|
||||
Columns 25 through 28
|
||||
|
||||
3.1820e+00 3.3541e+00 4.2426e+00 6.0000e+00
|
||||
|
||||
Columns 29 through 32
|
||||
|
||||
0 0 0 0
|
||||
|
||||
Columns 33 through 35
|
||||
|
||||
0 0 0
|
||||
|
||||
|
||||
======================================================================================================
|
||||
======================================================================================================
|
||||
|
||||
|
||||
2. Aufruf von main(2) liefert:
|
||||
==============================
|
||||
|
||||
>> main(2)
|
||||
|
||||
e =
|
||||
|
||||
2.2204e-16
|
||||
|
||||
|
||||
p =
|
||||
|
||||
Columns 1 through 4
|
||||
|
||||
3.0000e+00 3.1058e+00 3.1326e+00 3.1394e+00
|
||||
|
||||
Columns 5 through 8
|
||||
|
||||
3.1410e+00 3.1415e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 9 through 12
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 13 through 16
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 17 through 20
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 21 through 24
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 25 through 28
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 29 through 32
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
Columns 33 through 35
|
||||
|
||||
3.1416e+00 3.1416e+00 3.1416e+00
|
||||
|
||||
|
||||
|
||||
=> Bei den beiden Aufrufen wird sichtbar, dass bei Verfahren 1 die Rundungsfehler in Maschinenarithmetik ab Iteration 21 die Annäherung an PI stark verfälschen. Ab Iteration 29 erhalten wir hier sogar 0. Verfahren 2 hingegen liefert in Maschinenarithmetik eine gute Annäherung an PI. Selbst bei Iteration 100 (hier nicht aufgeführt) erhalten wir den Wert 3.1416e+00 als Näherung für PI. Die Plots in Matlab veranschaulichen die Ergebnisse zudem graphisch.
|
||||
Somit sollte also Verfahren 2 für eine Annäherung an PI in Maschinenarithmetik verwendet werden.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
18
ws2012/CE/uebungen/P2/P2Matlab/main.m
Normal file
18
ws2012/CE/uebungen/P2/P2Matlab/main.m
Normal file
@ -0,0 +1,18 @@
|
||||
function [ output_args ] = main(type)
|
||||
%MAIN Spezifiziert einen Unit-Test fuer die 2. Programmieraufgabe
|
||||
|
||||
%Setzt das Format fuer Ausgabe (wissenschaftliche Darstellung)
|
||||
format shortE
|
||||
|
||||
%Aufruf der Benutzer-definierten Funktionen
|
||||
%Teilaufgabe a): Finde die kleinste Zahl, so dass (1.0+eps>1.0)
|
||||
e = findeps()
|
||||
|
||||
%Teilaufgabe b): Berechne eine Approximation an PI
|
||||
%fuer type =1 oder type=2
|
||||
p = approxpi(35, type)
|
||||
|
||||
%Grafische Darstellung
|
||||
plot(p, '--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
|
||||
|
||||
end
|
||||
27
ws2012/CE/uebungen/P2/P2Scilab/approxpi.m
Normal file
27
ws2012/CE/uebungen/P2/P2Scilab/approxpi.m
Normal file
@ -0,0 +1,27 @@
|
||||
function [ p ] = approxpi(n, type)
|
||||
//APPROXPI Approximates PI based on edge lengths e
|
||||
|
||||
|
||||
//vektor p:
|
||||
p = zeros(1, n);
|
||||
|
||||
//vektor edges:
|
||||
edge = zeros(1, n);
|
||||
edge(1) = 1;
|
||||
|
||||
for i=1:1:n
|
||||
select type
|
||||
case 1
|
||||
//Behandlung für ersten Fall
|
||||
edge(i+1) = sqrt(2 - sqrt(4-edge(i)^2));
|
||||
case 2
|
||||
//Behandlung für zweiten Fall
|
||||
edge(i+1) = edge(i) / sqrt(2 + sqrt(4-edge(i)^2));
|
||||
else
|
||||
disp('Wrong type!');
|
||||
end
|
||||
p(i) = 3*2^(i-1)*edge(i);
|
||||
end
|
||||
|
||||
endfunction
|
||||
|
||||
19
ws2012/CE/uebungen/P2/P2Scilab/findeps.m
Normal file
19
ws2012/CE/uebungen/P2/P2Scilab/findeps.m
Normal file
@ -0,0 +1,19 @@
|
||||
function [eps] = findeps()
|
||||
//FINDEPS Findet die kleinste Zahl eps>0, so dass 1+eps!= 1
|
||||
|
||||
|
||||
eps = 1;
|
||||
n = 1;
|
||||
while (1.0 + eps) > 1.0
|
||||
n = n + 1; //n erhöhen
|
||||
eps = 2^(-n); //eps neu zuweisen
|
||||
end
|
||||
|
||||
//einen Schritt der while-Schleife ""rückgängig"" machen, um das letzte eps zu
|
||||
//berechnen, so dass gerade noch gilt (1.0 + eps) > 1.0
|
||||
n = n - 1;
|
||||
eps = 2^(-n);
|
||||
|
||||
|
||||
endfunction
|
||||
|
||||
18
ws2012/CE/uebungen/P2/P2Scilab/main.m
Normal file
18
ws2012/CE/uebungen/P2/P2Scilab/main.m
Normal file
@ -0,0 +1,18 @@
|
||||
function [ output_args ] = main(type)
|
||||
//MAIN Spezifiziert einen Unit-Test fuer die 2. Programmieraufgabe
|
||||
|
||||
//Setzt das Format fuer Ausgabe (wissenschaftliche Darstellung)
|
||||
format("e",8)
|
||||
|
||||
//Aufruf der Benutzer-definierten Funktionen
|
||||
//Teilaufgabe a): Finde die kleinste Zahl, so dass (1.0+eps>1.0)
|
||||
e = findeps()
|
||||
|
||||
//Teilaufgabe b): Berechne eine Approximation an PI
|
||||
//fuer type =1 oder type=2
|
||||
p = approxpi(35, type)
|
||||
|
||||
//Grafische Darstellung
|
||||
//plot(p, '--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
|
||||
|
||||
endfunction
|
||||
Binary file not shown.
BIN
ws2012/P2P/Folien/Lecture_1.pdf
Normal file
BIN
ws2012/P2P/Folien/Lecture_1.pdf
Normal file
Binary file not shown.
Binary file not shown.
BIN
ws2012/P2P/Papers/Kademlia/109.pdf
Normal file
BIN
ws2012/P2P/Papers/Kademlia/109.pdf
Normal file
Binary file not shown.
BIN
ws2012/P2P/Papers/Kademlia/a23-wang.pdf
Normal file
BIN
ws2012/P2P/Papers/Kademlia/a23-wang.pdf
Normal file
Binary file not shown.
BIN
ws2012/P2P/Papers/Kademlia/kad_springer.pdf
Normal file
BIN
ws2012/P2P/Papers/Kademlia/kad_springer.pdf
Normal file
Binary file not shown.
BIN
ws2012/P2P/uebungen/6/u3.pdf
Normal file
BIN
ws2012/P2P/uebungen/6/u3.pdf
Normal file
Binary file not shown.
BIN
ws2012/P2P/uebungen/7/exercise7.pdf
Normal file
BIN
ws2012/P2P/uebungen/7/exercise7.pdf
Normal file
Binary file not shown.
BIN
ws2012/P2P/uebungen/7/exercise7_solution.odt
Normal file
BIN
ws2012/P2P/uebungen/7/exercise7_solution.odt
Normal file
Binary file not shown.
BIN
ws2012/P2P/uebungen/7/exercise7_solution.pdf
Normal file
BIN
ws2012/P2P/uebungen/7/exercise7_solution.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user