How to extract the coefficient of x inside the exponential?

5 Ansichten (letzte 30 Tage)
syms x
a1=10.0548; a2=-4.4425; a3=-3.2730; a4=-2.2430; b1=0.0; b2=0.0029; b3=0.0379; b4=0.3863;
y=a1*exp(-b1*x) + a2*exp(-b2*x) + a3*exp(-b3*x) + a4*exp(-b4*x);
z4 = expand(y4^2);
z4 = vpa(z4,6);
z4 = exp(-0.0758168 x) 10.7127 - exp(-0.0379084 x) 65.8191 - exp(-0.00294242 x) 89.3358 + exp(-0.00588485 x) 19.7354
- exp(-0.386332 x) 45.1049 + exp(-0.772664 x) 5.03086 + exp(-0.0379084 x) exp(-0.00294242 x) 29.0805
+ exp(-0.0379084 x) exp(-0.386332 x) 14.6825 + exp(-0.00294242 x) exp(-0.386332 x) 19.9285 + 101.099
[c, tx] = coeffs(vpa(z2,6))
qc = arrayfun(@char, tx, 'uniform', 0)
fin = cellfun(@(x)regexprep(x, '\<exp', ''), qc, 'UniformOutput', false)
fin1 = cellfun(@(x)regexprep(x, '\<x', ''), fin, 'UniformOutput', false)
fin2 = cellfun(@(x)regexprep(x, '*+', ''), fin1, 'UniformOutput', false)
fin3 = cellfun(@(x)regexprep(x, '\<(', ''), fin2, 'UniformOutput', false)
fin4 = cellfun(@(x)regexprep(x, '\>)', ''), fin3, 'UniformOutput', false)
fin5 = str2double(fin4)
It gives fin4 as
'-0.037908413650000305494813801487908-0.0029424243719999854107527426094748' '-0.037908413650000305494813801487908-0.38633213039999958482439978979528' '-0.037908413650000305494813801487908' '-0.075816827300000610989627602975816' '-0.0029424243719999854107527426094748-0.38633213039999958482439978979528' '-0.0029424243719999854107527426094748' '-0.0058848487439999708215054852189496' '-0.38633213039999958482439978979528' '-0.77266426079999916964879957959056' '1'
It gives fin5 as
NaN NaN -0.0379 -0.0758 NaN -0.0029 -0.0059 -0.3863 -0.7727 1.0000
Is there any better way to get the coefficennt of x inside the exponetial ?
Thank you.

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 9 Mai 2020
Bearbeitet: David Goodmanson am 9 Mai 2020
Hi Ishan,
Squaring y gives 16 terms involving the product of two exponential functions. Multilying exponentials means adding the two b coefficients in each product, so the task comes down to finding all possible sums of two b coefficients.
b = -[0.0 0.0029 0.0379 .3863];
cof = b+b'
% and if you want just the unique ones,
ucof = unique(cof(:))
ucof =
-0.7726
-0.4242
-0.3892
-0.3863
-0.0758
-0.0408
-0.0379
-0.0058
-0.0029
0
  2 Kommentare
Ishan Khatri
Ishan Khatri am 9 Mai 2020
Hi David,
Thnak you for such a lucid solution. How I can modify this code to fit cube and fourth power of y?
David Goodmanson
David Goodmanson am 10 Mai 2020
Hi Ishan,
here is one way. Start with a variation of the original process:
b = -[0.0 0.0029 0.0379 .3863];
bsum = b'; % create a column vector, one sum
bsum = bsum + b % create a matrix of all pairs of sums
bsum = bsum(:); % create a column vector, two sums
Now you just repeat the process to get column vectors of three sums, etc. and use unique at the end if desired.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by