## Find where an InterpolatingFunction reaches over a certain value

I used NDSolve in order to solve some PDE, and got a solution $$u(x,t)$$ in the type of InterpolatingFunction.

I know that $$u(x,t)$$ is strictly monotonically decreasing in $$x$$ at all times $$t$$ (namely $$\forall t \quad x_1\!). My goal is to calculate, for each time $$t$$, what is the minimal value $$x_0$$ that satisfies $$u(x_0,t) \leq u_0$$ for some constant $$u_0$$.

What I tried is

xt = {}; For[t = 0.1, t <= 10, t = t + 0.1,  x0 = NSolve[u[x, t] == u0, x];  xt = Join[xt, {{x /. x0[[1]], t}}];  ] 

but apart from probably being inefficient, I am afraid NSolve is not the appropriate function here (since it does not exploit my knowledge of monotony). Any other suggestions?

By the way, I know where $$x_0$$ should approximately be, so I tried also FindRoot with this initial guess, but it was not any better.

Thanks a lot!

## MATE – Language swtiching using shortcut stops once it reaches the last language in the list

I had 3 languages (EN, RU, HE) which were switched by win+space and everything worked fine. Now I have added SK to the list, and once the cycle comes to SK it never continues to the start of the list, while this works perfectly with alt+shift. I guess something is wrong with win key on Slovak layout, could you please give some directions on how to fix this? Attached layout configuration. Ubuntu 18.04.2 LTS, MATE 1.20.1

## What is the best way to write a loop that never reaches it’s end (continue/return) in python

# Standard multi choice question template def multiChoiceQuestion(options: list):     while True:         print("\nEnter the number of your choice - ")         for x in len(options):             print(str((x + 1)) + ". " + options[x])         print("\n")         try:             answer = int(input())         except ValueError:             print("Doesn't seem like a number! Try again!")             continue         if answer < 1 or answer > len(options):             print("That option does not exist! Try again!")             continue         return answer 

I created a template to ask a multi choice question in python. The loop will never reach it’s end, since there is always a continue or a return statement. Is the while True condition appropriate for it?

## What happens if a wizard reaches level 20 but has no 3rd-level spells that they can use with the Signature Spells feature?

At level 20, a wizard gains the Signature Spells feature. This allows them to choose two 3rd-level spells, and from then on they always have those spells prepared and can cast them once each without using a spell slot between rests.

What happens though, if a wizard reaches level 20 and does not have two 3rd-level spells in their spellbook for some reason? Is the ability suspended until they scribe two such spells in their spellbook?

## sql – rolling sum till it reaches certain value and calculate duration

I have a requirement where I need to know when the sum(value) reaches certain point and calculate duration. Below is the sample table.

create table sample (dt timestamp, value real); insert into sample values (‘2019-01-20 00:29:43+00 ‘,0.2948),(‘2019-01-20 00:35:06+00 ‘,0.2948),(‘2019-01-20 00:35:50+00 ‘,0.2948), (‘2019-01-20 00:36:32+00 ‘,0.2948),(‘2019-01-20 00:37:20+00 ‘,0.2948),(‘2019-01-20 00:41:30+00 ‘,0.4261), (‘2019-01-20 00:42:28+00 ‘,0.4261),(‘2019-01-20 00:43:14+00 ‘,0.4261),(‘2019-01-20 00:44:18+00 ‘,0.4261);

select * from sample order by dt; dt | value
———————+——–

2019-01-20 00:29:43 | 0.2948

2019-01-20 00:35:06 | 0.2948

2019-01-20 00:35:50 | 0.2948

2019-01-20 00:36:32 | 0.2948

2019-01-20 00:37:20 | 0.2948

2019-01-20 00:41:30 | 0.4261

2019-01-20 00:42:28 | 0.4261

2019-01-20 00:43:14 | 0.4261

2019-01-20 00:44:18 | 0.4261

Now my requirement is to calculate cumulative sum of next records to see when the sum(value) reaches above 1.0 (it can be 1 records or n number of records) and once I find that point, I need to calculate time difference between current record and record where sum(value) reaches 1.

Essentially I want output in below format.

     dt         | value | sum(value)| time_at_sum(value)_1| Duration 

———————+——–+——————————————

2019-01-20 00:29:43| 0.29 | 1.01 | 2019-01-20 00:35:50 | 00:06:07

2019-01-20 00:35:06| 0.31 | 1.31 | 2019-01-20 00:37:20 | 00:02:14

2019-01-20 00:35:50| 0.41 | 1.00 | 2019-01-20 00:37:20 | 00:01:30

2019-01-20 00:36:32| 0.26 | 1.01 | 2019-01-20 00:41:30 | 00:04:58

2019-01-20 00:37:20| 0.33 | 1.10 | 2019-01-20 00:42:28 | 00:05:08

2019-01-20 00:41:30| 0.42 | 1.29 | 2019-01-20 00:43:14 | 00:01:44

2019-01-20 00:42:28| 0.35 | 1.12 | 2019-01-20 00:44:18 | 00:01:50

2019-01-20 00:43:14| 0.52 | NULL | – | –

2019-01-20 00:44:18| 0.25 | NULL | – | –

Anyone has ideas or pointers on how to deal with above requirement?

## TableView: Get Notified When Scroll Reaches Bottom/ Top of Table

I can listen for scroll events:

tableView.addEventFilter(javafx.scene.input.ScrollEvent.SCROLL,         new EventHandler<javafx.scene.input.ScrollEvent>() {             @Override             public void handle(final javafx.scene.input.ScrollEvent scrollEvent) {             System.out.println("Scrolled.");              }         }); 

But How can I be notified if the bottom/ top of the table is reached?

## Add a new row to a spreadsheet, copying down formulas when a certain cell reaches a particular value

I’ve got a simple Google Sheet (it’s literally one line), that has in A2 =now() to calculate the current time, and then a series of formulas calculating various dates/times based on the current date in column A2 all the way to column R (column 18)

What I’d like to do is for when cell J2 reaches the value of “8” is to insert a new row and copy down the formulas from A2 to R2 into the new row, which would run every month.

How do I script this? I have no scripting experience.

I’ve been scouring the posts around here and have managed to cobble together some script that works:

 function copyFormatAndFormulas(rangeSource, rangeDestination) {    rangeSource.copyTo(rangeDestination, {formatOnly: true});    var formulas = rangeSource.getFormulasR1C1();    for(var x in formulas) {      for(var y in formulas[x]) {        if(formulas[x][y] == "") continue;        rangeDestination.getCell(parseInt(x) + 1, parseInt(y) + 1).setFormulaR1C1(formulas[x][y]);}}}   function addRow() {       var ss = SpreadsheetApp.getActive();     var NameofSpreadsheet = ss.getName();   // if(NameofSpreadsheet == 'Email Triggers') { //checks that we're on the correct sheet, although can't seem to get it working      var WorkingDaysLeft = 8;      var sheet = ss.getSheetByName('Email Triggers'); // the current sheet       var range = sheet.getRange(2,10,1,1); // looking for cell J2      var data = range.getValue(); // getting the value of cell J2      if (data == WorkingDaysLeft) { //checking the value of cell J2 to WorkingDaysLeft, if it equals 8 then run the next functions to insert new row and copy down formulas         var sh = ss.getActiveSheet(),//            lRow = sh.getLastRow();         var lCol = sh.getLastColumn(),            range = sh.getRange(lRow,1,1,lCol);        sh.insertRowsAfter(lRow,1);        var newRange = sh.getRange(lRow+1,1,1,lCol);        copyFormatAndFormulas(range, newRange);      }} 

I’d like to have a conditional IF statement to ensure that I am on the correct spreadsheet, as there are other sheets in the workbook. Any ideas what I’m doing wrong here?