solve for elimination constant K - excel

Can someone show me how to isolate K in the following equation? (I want to use excel to find K, and I will know a,b,c,d,and f, so I need K isolated):
a = (b/c * exp(-K*d)+a)*exp(-Kf)

Related

Is there any method/solver in python to solve embedded derivatives in a ODE equation?

I've got this equation from mathematical model to know the thermal behavior of a battery.
dTsdt = Ts * a+ Ta * b + dTadt * c + d
However, i can't get to solve it due to the nested derivatives.
I need to solve the equation for Ts and Ta.
I tried to define it as follows, but python does not like it and several eŕrors show up.
Im using scipy.integrate and the solver ODEint
Since the model takes data from vectors, it has to be solved for every time step and record the output accordingly.
I also tried assinging the derivatives to a variable v1,v2, and then put everything in an equation without derivatives like the second approach shown as follows.
def Tmodel(z,t,a,b,c,d):
    Ts,Ta= z
    dTsdt = Ts*a+ Ta*b + dTadt*c+ d
    dzdt=[dTsdt]
    return dzdt
z0=[0,0]
# solve ODE
for i in range(0,n-1):
   
    tspan = [t[i],t[i+1]]
    # solve for next step
    z = odeint(Tmodel,z0,tspan,arg=(a[i],b[i],c[i],d[i],))
    # store solution for plotting
    Ts[i] = z[1][0]
    Ta[i] = z[1][1]
    # next initial condition
    z0 = z[1]
def Tmodel(z,t,a,b,c,d):
    Ts,v1,Ta,v2= z
# v1= dTsdt
# v2= dTadt
    v1 = Ts*a+ Ta*b + v2*c+ d
    dzdt=[v1,v2]
    return dzdt
That did not work either.I believe there might be a solver capable of solving that equation or the equation must be decouple in a way and solve accordingly.
Any advice on how to solve such eqtn with python would be appreciate it.
Best regards,
MM
Your difficulty seems to be that you are given Ta in a form with no easy derivative, so you do not know where to take it from. One solution is to avoid this derivative completely and solve the system for y=Ts-c*Ta. Substitute Ts=y+c*Ta in the right side to get
dy/dt = y*a + Ta*(b+c*a) + d
Of course, this requires then a post-processing step Ts=y+c*Ta to get to the requested variable.
If Ta is given as function table, use an interpolation function to get values at any odd time t that is demanded by the ODE solver.
Ta_func = interp1d(Ta_times,Ta_values)
def Tmodel(y,t,a,b,c,d):
Ta= Ta_func(t)
dydt = y*a+ Ta*(b+c*a) + d
return dydt
y[0] = Ts0-c*Ta_func(t[0])
for i in range(len(t)-1):
y[i+1] = odeint(Tmodel,y[i],t[i:i+2],arg=(a[i],b[i],c[i],d[i],))[-1,0]
Ts = y + c*Ta_func(t)

Rank elements based off two variables

I want to rank all the entities in a list based of two variables (both percentages). One of the variables is 'the bigger the better' (x) and the other is 'smaller the better' (y). What is the best way to give each entity a score in order to rank them?
I tried doing x*(1-y) but as some of the y values are over 1, the negatives it created caused some errors.
Below is the data:
x y
a 0.953882755 0.926422663
b 0.757267676 0.926967001
c 1 1.01607838
d 0.89805254 1.008814817
e 0.672989727 0.932579014
f 0.643306278 0.924523932
g 0.621091809 0.935122957
h 0.56891321 0.918181342
i 0.563662125 0.924102288
j 0.579410248 0.946421415
k 0.781299906 1.040418561
l 0.490013047 0.920900829
m 0.475050754 0.932586282
n 0.505211144 0.972570665
o 0.566582462 1.009732948
p 0.610994363 1.031047605
q 0.686065983 1.060742126
r 0.47642017 0.983301498
s 0.463552006 0.976645044
t 0.551532341 1.025816246
u 0.478092524 1.012675037
v 0.645790431 1.084143812
w 0.390365014 1.189518019
Two ways : averaged ranking OR sort by distance from min&max
average ranking :
use =RANK.AVG() on X & Y separately. Get the average, then rank again base on the average.
sort by distance from min&max :
do '=(B2-MIN(B:B)) + (MAX(C:C)-C2)' and drag downwards. Then use =RANK.AVG() on the results, being the smaller (the distance from min/max) the better.
Hope it solves.

Find second argument from first argument in a list

I have the following problem: let L be a list ( (i,j), w_i,j ) for i and j between 1 and N. Suppose we know the couple (i,j) (for example : (5,8)), is there a way to find w_5,8 only from the list L?
NB: my code is a priori better if I use the liste L instead of a matrix w[i][j], since it is mostly empty, so I would rather not use such a matrix.
Thanks in advance
There are many ways to store and lookup values of a (sparse) matrix, which I assume is the goal here.
Option 1
Do not attempt to optimize to early. Depending on what kind of computations you want to perform on the matrix you may be best advised to simply use a numpy array and do not worry about sparseness.
If your matrix is really large and indeed sparse you can use the specialised sparse matrix implementations of scipy.
Option 2
You already have the list L in the format you described and you do not want to use any of the numeric packages mentioned above. Then you can convert L into a dictionary for easy value lookup:
# example list
L = [((1,2), 456.5), ((5,4), 33.5)]
# convert to dictionary
D = dict(L)
# lookup
v = D[(1,2)] # v is now 456.5
# missing value
v = D[(3,3)] # throws KeyNotFound exception
# convert to dictionary with default value for missing keys
from collections import defaultdict
D = defaultdict(int, L)
# lookup
v = D[(1,2)] # v is now 456.5
# missing value
v = D[(3,3)] # v is now 0

What is the approach to solve spoj KPMATRIX?

The problem link is here. The problem is basically to count all such sub matrices of a given matrix of size N by M, whose sum of elements is between A and B inclusive. N,M<=250. 10^-9<=A<=B<=10^9.
People have solved it using DP and BIT. I am not clear how.
First, i tried to solve a simpler version, 1-D case of the above problem: Given an array A, of length N, count all subarrays, where sum of elements in the subarray lies between A and B, but still couldn't think of better than O(n^2). Here is what i did :
I thought of making another array for keeping prefix sum of the original array, say prefix[N]. prefix[i] = A1 + A[2] + A[3] + ...A[i]. set prefix[ 1] = A [ 1]. Then for each i from 2 to N, problem is to count all j <= i such that sum Z = A[j] + A[j+1] + ..A[i] lies between A and B. This is equivalent to prefix[i] - prefix[j-1]. But it's still O(n^2), as for each i, j is hitting i places.
can anybody help me step by step to advance me in the given approach to solve the main problem ?.

SAS search for value of variable

I am relatively new to SAS with limited programming experience. I need to write code that searches for the value of a specific variable that will form an equality. For example, I need to find the value of k that makes the following algebraic equation hold:
A = B + {[(C - k(B)] / (1+k)} + {[(D - k(E)] / (1+k)^2}, etc.
In this equation, I know the values of A, B, C, D, etc. and need to search for a value of k (the discount rate) that fits the equality.
Here's the proc model code I'm trying to use:
proc model data = test noprint;
p = bv0 + ((e1 - (k * bv0)) / (1+k)) + ((e2 - (k * bv1)) / ((1+k)**2)) + ((e3 - (k * bv2)) / ((1+k)**3)) + ((e3 - k *(bv2)) * (1+g)) / (((1+k)**3) * (k - g));
ENDOGENOUS k;
solve k / out = est;
run;
When I run this code, I receive the following error message:
WARNING: No equations are defined in the model. (Check for missing VAR or ENDOGENOUS statement.)
ERROR: The following solve variables do not appear in any of the equations to be solved: k
Any help anyone can provide would be great! Thanks!
If p is supposed to be the name of an equation, try adding eq. prefix before p. If p is a variable that the expression on the right should be equal to, then replace p with eq.equation1 and put -p on the right side.

Resources