Message Boards Message Boards

0
|
4569 Views
|
16 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Impossible manipulation

Posted 9 years ago

Hi everybody, I can't solve a following problem. There is one formula:

Q = a * (AX - b) + BX * c + d * CX + f * (DX - FX),

where a, b, c, d, f, g - constants, which values are unknown, but areas of values (from-to) are defined, so I could manipulate their; AX, BX, CX, DX, EX - known lists of data; FX - a list of data, which values are also unknown: FX[i + 1] = FX[ i ] + 2 * (f / g) * (EX[[ i ]] - FX[ i ]), FX[1]=EX[[1]]; My target: to get Q through manipulate of constants (fit with another graphic). The problem: as long as FX is not found Mathematica can't manipulate constants.

I would be glade your help and ideas...

Here I have an error message (see also attachments)

Manipulate[FX[1] = EX[[1]]; 
 FX = Table[
   FX[i + 1] = FX[i] + 2 (f/g)*(EX[[i]] - FX[i]), {i, 1, Length[EX]}];
  ListLinePlot[a*(AX - b) + c*BX + d*CX + f*(DX - FX), Frame -> True, 
  PlotRange -> All, 
  FrameLabel -> {Style[Time [s], 12, Bold], 
    Style[TotalPower [W], 12, Bold]}, ImageSize -> 1000], {{g, 5}, 5, 
  700, 1}, {{f, 1}, 1, 20, 0.01}, {{a, 0}, 0, 500, 1}, {{c, 0}, 0, 5, 
  0.01}, {{b, 0}, -0.1, 0.1, 0.001}, {{d, 400}, 400, 800, 5}]

And here the proces hangs

FX[1] = EX[[1]]; FX = 
 Table[FX[i + 1] = FX[i] + 2 (f/g)*(EX[[i]] - FX[i]), {i, 1, 
   Length[EX]}]
Attachments:
POSTED BY: Leo James
16 Replies
Posted 9 years ago

Guten Abend Hans. Es gibt eine ideale Kurve, die mir bekannt ist. Q ist eine zeitlich abhängige Kurve,die ich aus experimentellen Daten sowie durch Manipulation der Konstanten bekomme. Aber nun klappt es mithilfe der Methode von Gianluca. Ich bedanke mich bei Ihnen noch mal.

POSTED BY: Leo James

I am glad to be helpful. Did you find the right way to shorten the vector of length n+1?

POSTED BY: Gianluca Gorni
Posted 9 years ago

No, I didn't. But your method works!

POSTED BY: Leo James

Guten Abend Leo. Was genau ist denn das Problem? An was soll Q gefitted werden?

Gruß Hans

POSTED BY: Hans Dolhaine

Guten Abend Leo (ich bin auch aus D),

perhaps this may be helpful as well. At the end of thenotebook attached you find a function which gives the n-th Element of Vector Q.

The main problem seems to be that you have a sum over n elements of vector EF, which could get lengthy for big n. Perhaps one could speed that up by compiling.

Some remarks. It sounds that you try to fit your parameters a, b, ...to experimental data Q. What about for a first step extracting k times 6 Q's and using FindRoot to Solve for a,...,f. for each of these data extracted (form different regions of Q)? That could give a rough idea in which region of the parameters you should look. Or extracting randomly a couple of 100 data and use Fit. With fQ you now have a Function which could be fitted......

Grüße Hans

Attachments:
POSTED BY: Hans Dolhaine
Posted 9 years ago

Hallo Hans,

I thank you so much for making of generalization about my problem and also for time and energy which you spent for that. You showed me so much important things and I'll add they to my armoury.

It seems to be right that problem is n-elements in data EX less than this one in FX. That's why several logical things (also the last - vector) in this situation don't work.

A little bit about my aim here. Q is in contrast to EX not experimental data, must be calculated. And I unfortunatelly can't work with different regions of experimental data because on graphic for search Q through manipulation of constants I need to see the picture with all data to fit the line.

Thanks one more time for help!

POSTED BY: Leo James
Posted 9 years ago

Gianluca, I thank you very much, all funktionetes!

POSTED BY: Leo James

This variant with delayed definition seems faster:

With[{n = 20000}, EX = RandomReal[{0, 1}, n];
 AX = RandomReal[{0, 1}, n];
 BX = RandomReal[{0, 1}, n];
 CX = RandomReal[{0, 1}, n];
 DX = RandomReal[{0, 1}, n];
 FX[f_, g_] := Most@FoldList[#1 + 2 (f/g)*(#2 - #1) &, EX[[1]], EX];
 Manipulate[
  ListLinePlot[a*(AX - b) + c*BX + d*CX + f*(DX - FX[f, g]), 
   Frame -> True, PlotRange -> All, ImageSize -> 1000], {{g, 5}, 5, 
   700, 1}, {{f, 1}, 1, 20, 0.01}, {{a, 0.}, 0, 500, 1}, {{c, 0.}, 0, 
   5, 0.01}, {{b, 0.}, -0.1, 0.1, 0.001}, {{d, 400.}, 400, 800, 5}]]

Check out my use of Most, which may not be what you mean.

POSTED BY: Gianluca Gorni

I would use FoldList to build your FX. For vectors of length 1000 the following is not too slow:

With[{n = 1000},
 EX = RandomReal[{0, 1}, n];
 AX = RandomReal[{0, 1}, n];
 BX = RandomReal[{0, 1}, n];
 CX = RandomReal[{0, 1}, n];
 DX = RandomReal[{0, 1}, n];
 FX[f_, g_] = 
  Most@FoldList[Expand[#1 + 2 (f/g)*(#2 - #1)] &, EX[[1]], EX];
 Manipulate[
  ListLinePlot[a*(AX - b) + c*BX + d*CX + f*(DX - FX[f, g]), 
   Frame -> True, PlotRange -> All, ImageSize -> 1000], {{g, 5}, 5, 
   700, 1}, {{f, 1}, 1, 20, 0.01}, {{a, 0}, 0, 500, 1}, {{c, 0}, 0, 5,
    0.01}, {{b, 0}, -0.1, 0.1, 0.001}, {{d, 400}, 400, 800, 5}]]
POSTED BY: Gianluca Gorni
Posted 9 years ago

Thanks for your interesting variant. It really works for n=1000, but for 15000-20000 it's running until now...

I've just noted (f/g) is marked with dark blue and not light blue as all constants. So if I give values for f and g it works. But I want to manipulate these parameters.

Attachments:
POSTED BY: Leo James
Posted 9 years ago

Good morning Hans (I am from Germany too), thank you for your help. RSolve and even RecurrenceTable doesn't work (error; s. Attachments). If I use RecurrenceTable for Length about 20000 an error message arises.

Attachments:
POSTED BY: Leo James

Good morning Leo (here it is about 11 am), perhaps this will help you a bit:

In[21]:= RSolve[{F1X[i] ==    F1X[i - 1] + 2 f/g (E1X[i - 1] - F1X[i - 1]), F1X[1] == E1},  F1X[i], i]

To get rid of the somewhat annyoing K[1]

RSolve[{F1X[i] == F1X[i - 1] + 2 f/g (E1X[i - 1] - F1X[i - 1]),    F1X[1] == E1}, F1X[i], i] /. K[1] -> j

and even a bit more simplified

RSolve[{F1X[i] == F1X[i - 1] + 2 f/g (E1X[i - 1] - F1X[i - 1]),    F1X[1] == E1}, F1X[i], i] //. {-g Sum[XX_, YY_] :> Sum[g XX, YY], 
  K[1] -> j}
Attachments:
POSTED BY: Hans Dolhaine
Posted 9 years ago

It's a nice idea. But how do I define j?

POSTED BY: Leo James

hmmmm.

perhaps you can construct a function of a, b, ... for each i.

a * (AX - b) + BX * c + d * CX is I think sort of linear in a, b, c, ...

Now look af FFX. Each component seems to be a polynomial in f / g. perhaps one can figure out a recursion relation for ( f / g )^j for each j. In this case you could avoid the really big tables....?

POSTED BY: Hans Dolhaine

I think your construction of FX ist not the real thing. What about ( with EX = {3, 6, 4, 8} for example )

FX[1] = EX[[1]];
FX[i_] := FX[i - 1] + 2 f/g (EX[[i - 1]] - FX[i - 1])

Which yields

In[10]:= FFX = 
 Table[FX[i + 1] = FX[i] + 2 (f/g)*(EX[[i]] - FX[i]), {i, 1, Length[EX]}] // Simplify


Out[10]= {3, 3 + (6 f)/g, 3 - (12 f^2)/g^2 + (8 f)/g,  3 + (24 f^3)/g^3 - (28 f^2)/g^2 + (18 f)/g}

and try your ListlinePlot with FFX (but don't use the definitions of FX in the Manipulate Object)

POSTED BY: Hans Dolhaine
Posted 9 years ago

Hey Hans, thank you so much for your quick reply! You're right - it works if "i" is not so large. But in my case "i" equates about 20000 and Mathematica is always running...

POSTED BY: Leo James
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract