# Matlab weird help

#### isro1

]As you can see in the photo, I have the values for A1..A7 and B1..B7.

Then, I plot a graph for the upper side A1..A7 and fit an exponential to it in Matlab. The eq is y=22.297e^-5.323x

After, I plot the graph for the lower side B1..B7 and fit an exponential to it. The eq is y=40.949e^-5.002x

The problem is that it is needed the same value for e's exponent. So it is needed that for A and B I get maybe something like y=22.297 e^-5.4x for both curves.

To do that I see that I can move the OX axis down/up and thus the y values for the A(x,y) and B(x,y) points change, making the equations for the curves change. But I want some kind of algorithm that can do this automatically until the exponents for e for both curves become as close as possible.

How can I make Matlab

1. fit the exponential curve for each graph (one for the As and one for the Bs)

2. check the values for e's exponent for the curves that correspond to the two graphs

3. find a value "d" to ad/subtract from the y values of the A(x, y) and B(x, y) so that now it has A(x, y+d) b(x, y+d)

4. do 1 and 2 again and see if the values for e's exponent for both curves have become equal or at least as close as possible.

5. show that value "d".

Thank you!

Last edited:

#### guinster

Hi
I was intrigued by your query.
Your data appears to be the envelope for a decaying sinusiodal waveform.
The y intercepts should be equal either side of zero ie y = +/-Vexp(-at)
so V the amplitude and a the decay constant need to be numerically equal.
If the sinusoid has a phase shift I don't think it will give you the necessary affect.
Cheers

1 person

#### isro1

Hello,

My data is experimental and it is not exactly sinusoidal.

Also, when I gather the data I choose where the OX is, I do not have any reference so it's my choice where Y is 0. So if I put OX too "up" or too "down" then the curve equations for up and down have different exponents for "e" which means the position I chose is not that good.

That's why I need some sort of way to get those exponents as close to each other as possible for all my experimental trials.

#### guinster

Hi

Sorry I didn't catch on to what you were trying to do too well.

If you take logs of each side you get a linear equation of the type ln(y) = ln(A) - kt where A is the max on the y axis and k is the parameter you want to match (I think ?).

Would it help to combine the data (making the -ve values +ve) in this linear form and do a least squares fit.

k would be a 'best fit' for your exponant and ln(A) a 'best fit' for your intercept on the y axis.

Just a thought !

Regards

#### isro1

Thank you! I will try to do that and see what happens. Sorry that I am replying so rarely, I am working on other things at the same time and then coming back to this. Thanks again for your replies!

#### isro1

Ok, so it is not working...

I have another idea now... how about if I get the median or mode (most common) value for the graph and subtract/add that to the Y values?

But I have an issue with this... The data I am creating the graph based on is not continuous. For example my data for X is 1 2 3 4 5 6 7 8 9 10 11 12 but for Y it's 5, 4, -2, -5, -4, -2, 2, 3, 2, 1, -1, -2 etc. In this case the mode I want would be 0, but the value 0 isn't in my data range. How exactly can I get excel or Matlab to generate a new data range that contains continuous data based on the graph it generated with the data given? I basically need continuous data that would generate the same graph line that excel/matlab generates using the points given.

#### guinster

Hi isro1

As you are still working on this problem it would help me to have a data set to try things out on.

I am sure there is a way of handling these values to produce a suitable mathematical expression.

Look forward hearing further from you.

Regards

#### guinster

Hi Isro1

Thanks for the data.

Give me a couple of days to try some things and I will let you know what I come up with.

Regards