## optimal control – Dynamic programming for a cost function of \$exp\$ type

Suppose I have a finite horizon dynamic programming problem, i.e. I want to minimize the following expression

$$E(sum_{t=0}^Tg(X_t, U_t) + G(X_T)|X_0 = x_0)$$

The standard trick is to solve this via backward induction using that the optimal value function is given by

$$J_t(x_t) = min_{u_t} g(x_t, u_t) + E(J_{t+1}(X_{t+1})|X_{t+1}=x_t)$$

I have seen an example of the following form

$$E(exp(sum_{t=0}^Tg(X_t, U_t) + G(X_T))|X_0 = x_0)$$

The notes say, one should introduce $$V_t(x_t) = ln(J_t(x_t))$$

For $$T$$ I then get $$V_T(x_T)=ln(J_T(x_T)) = G(X_T)$$. What I don’t understand is how they derive the following:

$$V_t(x_t)=min_{u_t}ln(J_t(x_t))=min_{u_t}ln E(exp(g(x_t,u_t)J_{t+1}(X_{t+1})|X_{t}=x_t)$$

The second equality is puzzling me. How they derive this form?

## complex analysis – Is there such a holomorphic function?

I have a problem with a certain issu. How to check if there is a holomorphic, such that :

1. $$f(frac{1}{n})=frac{1}{sqrt{n}}$$ on $$Delta(0,1)$$

2. $$f(frac{3n}{3n+1})=0$$ on $$Delta(0,2)$$

Regarding the first example I thought to consider a function $$f(x)=sqrt{x} text{where} x=frac{1}{n}$$. From continuity we have $$f(0)=0$$. Is the theorem of identify shows that such function exists?

## custom functions in function file delete automatically daily

I have added some custom ajax calls and functionality on my WordPress site. I added code in function.php which is placed in wp_includes folder. It was working fine but from the last 2 weeks, my custom functions automatically removed from functions.php file.
what is the solution of this? I am new to WordPress. Any help would be highly appreciable.

## Please help me with the plotting of the following function?

Plot[Im[ComplexExpand[-0.0078125` i + 1.25` k –
0.0078125` Sqrt[1.` i^2 + 127999.99999999999` k^2]]], {k, 0, 6}]

## plotting – Plot defined function several times

``````f(x_) := x;
T = 2;
a0 = 2/T*Integrate(f(x), {x, -1, 1});
a(k_) := 2/T*Integrate(f(x)*Cos(2*Pi*k/T*x), {x, -1, 1});
b(k_) := 2/T*Integrate(f(x)*Sin(2*Pi*k/T*x), {x, -1, 1});
g(x_, n_) :=
a0/2 + Sum(a(k)*Cos(2*Pi*k/T*x), {k, 1, n}) +
Sum(b(k)*Sin(2*Pi*k/T*x), {k, 1, n});
``````

To look at all plots at once

``````ParametricPlot3D(
Evaluate({x, #, g(x, #)} & /@ Range(10)),
{x, -1, 1},
BoxRatios -> {1, 1, 1/2},
AxesLabel -> (Style(#, 14, Bold) & /@
{"x", "n", "g "}))
``````

To selectively look at each individual plot

``````Manipulate(
Plot(Evaluate@g(x, n), {x, -1, 1},
AxesLabel -> (Style(#, 14, Bold) & /@
{"x", "g"}),
PlotStyle -> ColorData(97)(n)),
{{n, 3}, Range(10), ControlType -> SetterBar})
``````

## entities – Fatal error: Uncaught Error: Call to undefined function file_save_data()

I have few PDF files that I want to save in Drupal with `file_save_data` function but when I run `drush cr` I get this error:
`Fatal error: Uncaught Error: Call to undefined function file_save_data()`

Here is my code:

``````<?php
use DrupalnodeEntityNode;
use DrupalfileEntityFile;
use DrupalCoreStreamWrapperPublicStream;

\$uploadedFilesPath = PublicStream::basePath() . '/import/program';
\$dataFiles = array();
\$files = array();

if (\$handle = opendir(\$uploadedFilesPath)) {
\$i = 0;
while (false !== (\$entry = readdir(\$handle))) {
if (\$entry != "." && \$entry != "..") {
\$dataFiles(\$i) = file_get_contents(\$uploadedFilesPath . "https://drupal.stackexchange.com/" . \$entry);
\$files(\$i) = file_save_data(\$dataFiles(\$i), PublicStream::basePath() . '/download/files');
\$i++;
}
}
closedir(\$handle);
}
\$random = 'sda';
``````

Any ideas how to fix that? I’m using Drupal version 8.9.11 and I wrote this code inside my custom module called csv_migration, in csv_migration.module file.

## python – Cannot assign to function call when looping through and converting excel files

With this code:

``````xls = pd.ExcelFile('test.xlsx')
sn = xls.sheet_names
for i,snlist in list(zip(range(1,13),sn)):
'df{}'.format(str(i)) =  pd.read_excel('test.xlsx',sheet_name=snlist, skiprows=range(6))
``````

I get this error:

‘df{}’.format(str(i)) = pd.read_excel(‘test.xlsx’,sheet_name=snlist,
skiprows=range(6))
^ SyntaxError: cannot assign to function call

`df+str(i)` also returns a error.

I want the result as:

``````df1 = pd.read_excel.. list1...
df2 = pd.read_excel... list2....
``````

## PYGAME – Sprite movement seize to function when entire X and Y span is reviewed

I’ve created an sprite class that has a detection radius checking if the player enters the zone. If yes, the sprite moves towards the player. It works perfectly fine when the sprite checks for three directions (X is greater, X is lower, Y is greater/lower), in other words, the sprite only moves up and down if all four directions are enabled..

Here is my code for the move function:

``````def move(self):
target_x, target_y = self.target.pos

if self.mob_wc + 1 <= 24:

if self.pos_x < target_x:
self.vel += vec(self.speed, 0)
self.image = self.game.orc_mob_walkRight(self.mob_wc//6)
self.mob_wc += 1

elif self.pos_x > target_x:
self.vel = vec(-self.speed, 0)
self.image = self.game.orc_mob_walkLeft(self.mob_wc//6)
self.mob_wc += 1

if self.pos_y > target_y:
self.vel = vec(0, -self.speed)
self.mob_wc += 1

elif self.pos_y < target_y:                   <-- if this condition is disabled
self.vel = vec(0, self.speed)                 The sprites move perfectly upwards
self.mob_wc += 1                              towards the player, shifting between
moving On X and moving on Y.
else:                                                     However, if it is enabled, the
self.mob_wc = 0                                       sprites ONLY move on the Y field

``````

Here is my code for the update function:

``````    def update(self):
self.rect = self.image.get_rect()
self.rect.center = self.pos
self.pos += self.vel * self.game.dt

self.pos_x, self.pos_y = self.pos

target_dist = self.target.pos - self.pos

if target_dist.length_squared() < self.detect_radi**2:
self.move()
else:
self.vel = vec(0,0)
self.image = self.game.orc_mob_img
``````

For the way they move i followed this post.
I am aware my build differs due to the use of vectors, which is something that i’m suspecting may be the cause of the issue. If anyone have any idea or tips to why this issue may occur, please tell me cause i’ve been sitting trying to fix this for 3+ hours now..

## ANGULAR 11 | Can’t execute function inside custom form validation.. why?

I have a Reactive Form in Angular 11 and I’m trying to execute a date parsing function inside the custom validator of my form but, I get an error on my browser terminal that says that the function is not defined.. It seems that the validator runs before the function definition.. but why? is there a solution to this?

My app works, I just repeated the code of the function inside the custom validator and everything is good.. but I shouldn’t have to repeat code…

the constructor of my .ts:

``````constructor(private navbarService: NavbarService) {
this.navbarService.showNavbar(true);
this.placeholderDate = new Date;

this.searchForm = new FormGroup({
fechaDesde: new FormControl('', (
Validators.required,
Validators.pattern(/^((0)?(1-9)|(1|2)(0-9)|(3)(0|1))(./-)((0)?(1-9)|(1)(0-2))(./-)((0-9){4})\$/)
)),
fechaHasta: new FormControl('', (
Validators.required,
Validators.pattern(/^((0)?(1-9)|(1|2)(0-9)|(3)(0|1))(./-)((0)?(1-9)|(1)(0-2))(./-)((0-9){4})\$/),
)),
}, (this.dateValidators))
``````

}

My date parsing function in the same .ts file:

`````` parseToDateFormat(date: string): Date {

const destructurDate = date.split('-');
if (destructurDate(0).length === 1) destructurDate(0) = '0' + destructurDate(0);
if (destructurDate(1).length === 1) destructurDate(1) = '0' + destructurDate(1);
let parsedDate = destructurDate.join('-');
const result = new Date(parsedDate.replace(/(d{2})-(d{2})-(d{4})/, "\$2/\$1/\$3"));
return result;
``````

}

My dateValidaors() function (all in the same components ts:

``````dateValidators(form: FormGroup) {
let fechaFrom = form.get('fechaDesde').value;
let fechaTo = form.get('fechaHasta').value;
fechaFrom = this.parseToDateFormat(fechaFrom);
fechaTo = this.parseToDateFormat(fechaTo);
if (fechaFrom <= fechaTo) return null;
``````

}

the error is :

ERROR Error: Uncaught (in promise): TypeError: can’t access property “parseToDateFormat”, this is undefined
dateValidators@http://localhost:4200/main.js:1811:5

Again, my solution was to just copy paste the logic of my parsing funtion inside the validator, but repeating code…

can someone explain please?

thanks!

## random – Python Turtle Race Restart Function

I just got done with my first Turtle Race and still had one assignment left, a restart function. I just cant get it to work as i want. The goal is, an output of a question: Restart? y or n, and that’ll restart the race() function and start a completly new race. I am really in need of your guys’ help.

``````from turtle import *
from random import randint

Andi = Turtle("turtle")
Andi.color("red")
Andi.shape("turtle")
Andi.penup()
Andi.goto(-300,200)
Andi.pendown()

Dom = Turtle("turtle")
Dom.color("green")
Dom.shape("turtle")
Dom.penup()
Dom.setpos(-300,180)
Dom.pendown()

Pete = Turtle("turtle")
Pete.color("blue")
Pete.shape("turtle")
Pete.penup()
Pete.setpos(-300,160)
Pete.pendown()

Emir = Turtle("turtle")
Emir.color("yellow")
Emir.shape("turtle")
Emir.penup()
Emir.setpos(-300,220)
Emir.pendown()

windowcolor=Screen()
windowcolor.bgcolor("black")

turtles = (Emir, Pete, Dom, Andi)
def race():
global turtles
winner = False
finishline = 300

while not winner:
for current_turtle in turtles:
move = randint(0, 10)
current_turtle.forward(move)
xcor = current_turtle.xcor()
if (xcor > finishline):
winner = True
current_turtle.forward(0)
winner_color = current_turtle.color()
print('The winner is', winner_color(1))
def restart():
global turtles
while race():
turtle.clear()
race ()
restart ()
while True:
while True:
answer = str(input("Restart? (y/n): "))
if answer in ("y", "n"):
break
print("Invalid awnser")
if answer == "y":
race
else:
print("Shutting off")
break

windowcolor.mainloop()

while True:
windowcolor.update()
``````

What am I doing wrong, in my restart() function?