Skip to main content
Tweeted twitter.com/StackMma/status/1345293768518471680
deleted 2 characters in body
Source Link

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with such definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with such definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with such definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?

added 35 characters in body
Source Link

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with my currentsuch definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with my current definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly?

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with such definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?

Became Hot Network Question
Formatted code, restructured text
Source Link
MarcoB
  • 67.7k
  • 18
  • 96
  • 198

Integral of thea function, defined with a loop

I'm new to Mathematica as well as functional programming. I believe that the solution to the following example-problem will help in my case. Definehave defined a function gg as

g[t_] := (
res=0;   res = 0;
i=1;   i = 1;
While[i<=t   While[i <= t,
res=res+i;     res = res + i;
i=i+1;     i = i + 1;
   ];
   res);

The aim is to well-define and later work with the function F[u]F[u], which should be an Integrala the integral of gg in bounds [0,u]$[0,u]$, something like

F[u_] :=Integrate[g[y]= Integrate[g[y], {y, 0, u}]

The problem is that in such form FHowever, the result I obtain for F is not correct andwith my current definition of g. In fact, F takes value 0 for any argument uu (my guess, is that this happens because g[y]g[y] is immediately evaluated as 0). Does anybody have the idea, how F

How can F be redefined properly?

Integral of the function, defined with a loop

I'm new to Mathematica as well as functional programming. I believe that the solution to the following example-problem will help in my case. Define a function g as

g[t_]:=(
res=0;
i=1;
While[i<=t,
res=res+i;
i=i+1;
];
res);

The aim is to well-define and later work with the function F[u], which should be an Integral of g in bounds [0,u], something like

F[u_]:=Integrate[g[y],{y,0,u}]

The problem is that in such form F is not correct and takes value 0 for any argument u (my guess, this happens because g[y] is immediately evaluated as 0). Does anybody have the idea, how F can be redefined properly?

Integral of a function defined with a loop

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be a the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with my current definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly?

Source Link
Loading