Solve an equation for a variable (algebra)

I have to solve for n, for this equation M = a + c (n-6). I've already used distributive property. However, I do not have similar terms. I've tried different ways to get the answer, but none seems to logically make sense. How would you settle that? Once again, I solve for n.

python – Implicit recursion when assigning a return function to a variable?

Hi guys, I started studying Python and I had a slightly strange behavior for me. It's like this: I have a file test.py which contains functions. In another file, exemple1.py I've imported this and other files as modules. In the archives exemple1.py I created 3 functions (func1, func2, func3). In func1 I pass in parameter: a list and the reference of a function defined in test.py.
In func1 I attributed the return of func2 to 3 variables, all with the same parameters for func2:

a = func2(x_best,h,0.1)
b = func2(x_best,h,0.1)
c = func2(x_best,h,0.1)

However, the variables receive the values ​​as if func2 was run 3 times, always receiving as his own return from the previous run. Another thing I realized is that if I declare only two variables, the values ​​assigned to the variables are the equivalent of two executions of the variable. func2 taking as parameters the return of the previous run. My question is: is there an implicit recursion based on the number of variables I declare ??? I am quite confused by these results.

Below, I will specify the codes of what I'm trying to say. I will omit certain functions because they do not interfere with the problem. Thank you in advance for your help.

test.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import json
from openpyxl import *
from random import *
from math import *

def beale ():
    return (1.5 - ponto(0)+ponto(0)*ponto(1))**2+(2.25-ponto(0)+ponto(0)*ponto(1)**2)**2+(2.625-ponto(0)+ponto(0)*ponto(1)**3)**2


def tgo(problema):

    pontos = points_generator(100)
    matriz = t_matriz_generator(pontos, problema)
    indices = list() 
    melhores = list()
    for i in range(len(matriz)):
        j = 0
        while (j < 4):
            if(matriz(i)(j) < 0):
                break
            if (j >= 3):
                indices.append(i)
            j += 1
    for a in indices:
        melhores.append(pontos(a))
    return melhores, problema

exemple1.py

from random import *
from teste import *
import math
import time

def LineSearch(Xtrial, Xbest, d, h):
    while (problema(Xtrial) < problema(Xbest)):
        Xbest = Xtrial
        h *= 2
        Xtrial(i)=trial_search(Xbest,h,d)
    return Xbest, h

def trial_search(ponto, h, d):
    FinalPoint = ponto
    for i in range(len(FinalPoint)):
        FinalPoint(i) = (FinalPoint(i)+h)*d
        if (problema(FinalPoint) < problema(ponto)):
            continue
        else:
            FinalPoint(i) = ponto(i)
    return FinalPoint

def Unirandi(x0, problema):
    tol = 0.0001
    h = 1.0
    fails = 0
    x_best = x0

    a = trial_search(x_best,h,0.1)
    b = trial_search(x_best,h,0.1)
    c = trial_search(x_best,h,0.1)




p, problema = tgo(beale)
Unirandi((-0.05338583452963963, 4.311503781033389),problema)

The values ​​for the variables are:

a -> (0.11094661416547036, 0.11531150378103339) 
b -> (0.11094661416547036, 0.11531150378103339) 
c -> (0.11094661416547036, 0.11531150378103339)

If I only declare

a = trial_search(x_best,h,0.1)
b = trial_search(x_best,h,0.1)

as a result I have:

a -> (0.10946614165470361, 0.15311503781033392) 
b -> (0.10946614165470361, 0.15311503781033392)

and finally if I just declare

a = trial_search(x_best,h,0.1)

following

a -> (0.09466141654703604, 0.531150378103339)

unit – Why does my "spawnedEnemies" variable fail to update when enemies are destroyed?

I create a shooter and I try to update the current number of enemies on the screen. When the laser hits an enemy, it is supposed to subtract 1 from the "enemies appeared" and then destroy the laser. What happens is that the spawnedEnemies number does not update in the game, but only when the game is over. Then, when the game is over, it displays a negative number. At the beginning of the game, 0 enemies appeared.

This is my EnemyController class. When "the enemy" is touched by a laser, it updates the int "spawned enemies" int of the GameManager class. But this does not update it in the game, but only when the game is over and it displays a negative number. Ex: I generate 5 enemies, I shoot all 5 and he shows -6 in the inspector.


     using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class EnemyController : MonoBehaviour
 {
     public GameManager theGM;

     // Start is called before the first frame update
     void Start()
     {
     }    

 private void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Laser")
         {
             theGM.spawnedEnemies = theGM.spawnedEnemies - 1;
             Destroy(this.gameObject);
         }
     }
 }

This is my GameManager class:


     using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class GameManager : MonoBehaviour
 {
     public int maxEnemiesAllowed;
     public int spawnedEnemies;
     public float timeBetweenEnemies;
     public float nextEnemySpawn;

     public GameObject() enemies;

     // Start is called before the first frame update
     void Start()
     {
         spawnedEnemies = 0;
     }

     // Update is called once per frame
     void Update()
     {
         float spawnPosition = Random.Range(-2.25f, 2.25f);

         if(spawnedEnemies <= maxEnemiesAllowed && Time.time >= nextEnemySpawn)
         {
             Instantiate(enemies(0), new Vector3(spawnPosition, 6f, 0f), Quaternion.identity);
             spawnedEnemies++;
             nextEnemySpawn = Time.time + timeBetweenEnemies;
         }
     }
 }

difference equations – How to specify an element of a list with a variable (RecurrenceTable)

My problem is that I'm trying to get a list of refractive angles in a multilayer structure (for the purpose of this example – with two types of refractive indices and eleven layers of these). The code is as follows:

theta0 = (1.535/2)*(Pi/180)
n = 11
nGaAs = 3.4;
nAlAs = 2.9;
nlayers = {1, nGaAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs, 
   nAlAs, nGaAs, nAlAs, nGaAs};
RecurrenceTable({theta(i) == 
   ArcSin((Extract(nlayers, i)/Extract(nlayers, i + 1))*
     Sin(theta(i - 1))), theta(0) == theta0}, theta, {i, 1, n})

I receive the following errors:

Extract::psl1: Position specification i in Extract({1,3.4,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4},i) is not applicable.

Extract::psl1: Position specification 1+i in Extract({1,3.4,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4},1+i) is not applicable.

Extract::psl1: Position specification 1+i in Extract({1,3.4,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4},1+i) is not applicable.

Is it possible to use a list of variables in RecurrenceTable? Since I'm pretty new to this field, I may have missed something in the description of RecurrenceTable or Extract, but does anyone know how to formulate it correctly in Mathematica?

replacement – Hiding variable names in function definitions

I have a problem where the alternate table variable name and similar functions may conflict with names in my function itself. Here is a minimal example

foo(a_) := 
 Probability(x > 0, x (Distributed) NormalDistribution(a, 1))

if i run

foo(-1)//N

I get the right answer (0.158655).

if I run instead (or use Table or similar)

foo(x) /. x->-1

I get 0 because the surrogate overrides x in the Probability arguments that are too foo to become Probability(-1>0,....

The obvious solution is not to use the same variable, but then I have to remember how I defined each function that I wrote and if I forget, I might make a mistake that can not be obvious.

With the extraction of a variable from the PHP function

I write code to comment, but the connection to the database is out of use, so it is necessary to put the code in the function. How can I extract the code?

include 'sis-config.php';
    include 'sis-checar.php';
    $conn = mysqli_connect($host, $usuario, $senha, $db);
    if (!$conn) {
    echo "Não foi possível conectar-se ao MySql." . PHP_EOL;
    exit;
    }
    function comentar()
    {
        include 'sis-config.php';
        $conn = mysqli_connect($host, $usuario, $senha, $db);
        if (!$conn) {
        echo "Não foi possível conectar-se ao MySql." . PHP_EOL;
        exit;
        }
        if (isset($_POST('comentar')))
        {
            $nome=$_POST('nome');
            $msg=$_POST('mensagem');
            $vrc1=checar($nome);
            $vrc2=checar($msg);
            $ip=$_SERVER('REMOTE_ADDR');
            $p = "INSERT INTO `chat` (`nome`, `ip`, `mensagem`, `vip`) VALUES ('$vrc1', '$ip', '$vrc2', '0');";
            if ($conn->query($p) === TRUE) {
                echo 'Postado com sucesso';
            } else {
             echo "Erro: " . $p . "
" . $conn->error; } } }

When I withdraw

include 'sis-config.php';
    $conn = mysqli_connect($host, $usuario, $senha, $db);
    if (!$conn) {
    echo "Não foi possível conectar-se ao MySql." . PHP_EOL;
    exit;

of the function, the query does not work, I want it to work without having to move the code inside the function

Include a variable in javascript

Hello,

I am new to javascript, can someone help me?

I want to add a variable in: var url
here I want to replace:
var url = "";

this variable is used in many pages and for each page has a different name … is not a fixed variable.

Thank you in advance for your help!

Regards,
floriano
SEMrush

cms – Refers to a domain variable of a MediaWiki website in the robots.txt file

I have a website (built with MediaWiki 1.33.0 CMS) that contains a robots.txt file.
In this file, there is a line containing the literal domain of this site:

Sitemap: https://example.com/sitemap/sitemap-index-example.com.xml

I generally prefer to replace literal domain references with a variable value call it will depend in some way (as the case may be) on the execution in value which corresponds to the domain itself.

An example for a CVV would be a Bash variable substitution.


Many CMSs have a global directive file that usually contains the basic address of the website:
In MediaWiki 1.33.0, this file is: LocalSettings.php which contains the basic address online 32:

$wgServer = "https://example.com";

How could I call this value with a variable value call in robots.txt?
This will help to avoid confusion and malfunction if the domain of the website is changed. I would not have to manually change the value there too.

cms – Refers to a domain of websites in the robots.txt file with a variable

I have a website (built with MediaWiki 1.33.0 CMS) that contains a robots.txt file.
In this file, there is a line containing the literal domain of this site:

Sitemap: https://example.com/sitemap/sitemap-index-example.com.xml

I generally prefer to replace literal domain references with a variable value call it will depend in some way (as the case may be) on the execution in value which corresponds to the domain itself.

An example for a CVV would be a Bash variable substitution.


Many CMSs have a global directive file that usually contains the basic address of the website:
In MediaWiki 1.33.0, this file is: LocalSettings.php which contains the basic address online 32:

$wgServer = "https://example.com";

How could I call this value with a variable value call in robots.txt?
This will help to avoid confusion and malfunction if the domain of the website is changed. I would not have to manually change the value there too.

c # – Call Library features with variable input number while keeping the API simple

For an ASP.NET Core application, I use a library that performs calculations using objects with a similar interface, but their constructors use different entries. Inputs are market prices and volatilities.

public class Base 
{
    public double Method1();
    public double Method2();
}

public class BaseOne : Base 
{
    public double Method1();
    public double Method2();
}

public class BaseTwo : Base 
{
    public double Method1();
    public double Method2();
}

public class ConcreteOneA : BaseOne
{
    public ConcreteOneA(double F, double V, double r, double K, ...);
    public double Method1() { // code }
    public double Method2() { // code }
}
public class ConcreteOneB : BaseOne
{
    public ConcreteOneA(double F, double V, double r, double K, ...);
    public double Method1() { // code }
    public double Method2() { // code }
}
public class ConcreteTwoA : BaseTwo
{
    public ConcreteOneA(double F1, double F2, double V, double r, double K, ...);
    public double Method1() { // code }
    public double Method2() { // code }
}

To create the ConcreteOne and ConcreteTwo classes, I need to extract the F, F1, F2, and V entries from a SQL Server database. I have an EF Core DbContext entity that is injected into an ASP.NET Core controller.

Whenever I wanted to perform calculations, my code was littered with queries and DbContext filters. In addition, I wanted to be able to use a single controller action to calculate the values ​​of Method1 and Method2 because these methods are similar to all Concrete classes and provide a convenient API for users. I have therefore created a factory class:

public class BaseFactory
{
    private MyContext _context;
    public BaseFactory(MyContext context)
    {
        _context = context;
    }
    public Base FromCode(MyDbEntity obj)
    {
        // use the context object to fetch F and V, and also F1 and F2 if the obj type is 3 
       //...

        // compute the other inputs for the concrete constructors which can be obtained directly from the MyDbEntity obj
       // ...

        switch (obj.Code)
        {
            case "1":
            case "4":
                return new ConcreteOneA(F, V, ....rest of the parameters computed from obj...
            case "5":
                return new ConcreteOneB(F,V, ....rest of the parameters computed from obj...);
            case "3":
                return new ConcreteTwoA(F1, F2, V, ......rest computed from obj.....);
        }
    }
}

Is this the right approach? The F is the price and V is the volatility that might have to come from a different data source in the future. So I might need to create another factory method for this specific source. But is it a good idea to make the factory dependent on this DbContext? My controller sends the injected DbContext to the factory when the controller is created:

(ApiController)
public class MyController
{
    public MyDbContext _context;
    private BaseFactory factory;
    public MyController(MyDbContext context)
    {
        _context = context;
        factory = new BaseFactory(_context);
    }
    (HttpGet('/route1'))
    public ActionResult MyMethodCompute(string code, double m, double s, double p)
    {
        // use _context to get MyDbEntity obj...

        return factory.FromCode(obj).Method1();
    }
}