Euler Slopes

dust's picture

here is an initial patch i made to solve a differential equation with the euler method. the assignment was to use newtons law of cooling and the euler method to predict if the coffee will cool faster if you add cream earlier or later. i haven't taken calc. i have just done predicate calc in logic class which is way different. so i made a basic graph with chart tools here using this equation . chart tools is awesome for this type of stuff by the way.

tempCoffe-newtK*deltaT*(tempCoffe - tempEnvironment)

was wondering if this looks right to anybody. i suppose using cl would be best for a large dataset. started making a euler kernel in cl. the way i want to do this is recursive but cl doesn't allow recursion. not sure if i got the cl kernel right, i'm going to convert it to temperature and then check against the other plot.

float4 Euler(float x, float y, float delta_x)
{
 
float slope = 2*x;
float change = slope * delta_x;
float4 eulerSlope = (float4)(x+delta_x,y+change,-0.f,0.f);
 
return eulerSlope;
 
}
 
__kernel void main(float x, float y, float delta_x, __global float4 *vertex)
{
 
   int  vec_x = get_global_id(0);
   int  vec_y = get_global_id(1);
   int  sz_x = get_global_size(0);
   int  sz_y = get_global_size(1);
 
   int index = vec_x * sz_y + vec_y;
   float4 t = Euler(x, y, delta_x);
 
   for(int i = 0; i < index ; i++)
   {
 
   t =    Euler(t.x, t.y, delta_x);
   }
 
 
 vstore4(make_float4(t.x,t.y,t.z,1.), (size_t)index, (__global float*)vertex);
 
 
 
}
PreviewAttachmentSize
do'c_euler_slope.qtz16.1 KB