Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a question about the size of a plot in mathematica. I'm working on some differential equations (a simplified model of heat transfer in a building). I've programmed it so that you can set initial temperatures using a slider. These initial temperatures then go through a series of calculaions, resulting in a graph with the sliders next to them, which looks like this: Plot 1

Now this is great, but the plot is a little small. Do you guys know if there's a way to make it show bigger by default? I can do it manually, but I would really like it to do so by itself, mainly because that way I can be sure it's always the same size, which looks neater in reports.

Also, even though I've used dynamic sliders, the graph doesn't change instantly. Presumably because the parameters are first used in a Solve-function, the results of which are used in the plot. Is there a way to make this graph plot the changes instantly?

The complete code looks like this.

    A := 3.8*10^-3 ( {
 {-6, 1, 1, 4},
 {1, -4, 1, 2},
 {1, 1, -4, 2},
 {0, 0, 0, 0}
} );
    (*Heat transfer coëfficient matrix, mostly dependant on wall area*)
    EVe = Eigenvectors[A];
    EVa = Eigenvalues[A];
    (*T1=;
    T2=;
    T3=;
    T4=;*)
    (*Use this part to manually enter initial temperatures if you want to overrule the slider*)
    s = Solve[
       EVe[[1, 1]] c1 + EVe[[2, 1]] c2 + EVe[[3, 1]] c3 + 
          EVe[[4, 1]] c4 == T1 && 
        EVe[[1, 2]] c1 + EVe[[2, 2]] c2 + EVe[[3, 2]] c3 + 
          EVe[[4, 2]] c4 == T2 && 
        EVe[[1, 3]] c1 + EVe[[2, 3]] c2 + EVe[[3, 3]] c3 + 
          EVe[[4, 3]] c4 ==  T3 && 
        EVe[[1, 4]] c1 + EVe[[2, 4]] c2 + EVe[[3, 4]] c3 + 
          EVe[[4, 4]] c4 == T4, {c1, c2, c3, c4}] ;
    (*Uses eigenvectors to solve for the needed coëfficients. There's probably a way to do this more efficiently using a for loop of some sort, but I don't know how.*)
    cc1 = c1 /. %;
    cc2 = c2 /. %%;
    cc3 = c3 /. %%%;
    cc4 = c4 /. %%%%;
    (*Assigns the values from Solve so they may be used later*)

    {{{VerticalSlider[Dynamic[T1], {0, 30}], Dynamic[T1]},
      {VerticalSlider[Dynamic[T2], {0, 30}], Dynamic[T2]},
      {VerticalSlider[Dynamic[T3], {0, 30}], Dynamic[T3]},
      {VerticalSlider[Dynamic[T4], {0, 30}], Dynamic[T4]}} , 
     Plot[{cc1*EVe[[1, 1]]*E^(EVa[[1]] t) + 
        cc2*EVe[[2, 1]]*E^(EVa[[2]] t) + cc3*EVe[[3, 1]] E^(EVa[[3]] t) + 
        cc4*EVe[[4, 1]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 2]]*E^(EVa[[1]] t) + cc2*EVe[[2, 2]]*E^(EVa[[2]] t) + 
        cc3*EVe[[3, 2]] E^(EVa[[3]] t) + cc4*EVe[[4, 2]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 3]]*E^(EVa[[1]] t) + cc2*EVe[[2, 3]]*E^(EVa[[2]] t) + 
        cc3*EVe[[3, 3]] E^(EVa[[3]] t) + cc4*EVe[[4, 3]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 4]]*E^(EVa[[1]] t) + cc2*EVe[[2, 4]]*E^(EVa[[2]] t) + 
        cc3*EVe[[3, 4]] E^(EVa[[3]] t) + 
        cc4*EVe[[4, 4]] E^(EVa[[4]] t)}, {t, 0, 500}, PlotRange -> All]}
    (*Plots results. Once again this could probably be done with a for loop, but I don't know how*)

Any help is greatly appreciated. Thanks in advance!

share|improve this question

1 Answer 1

Some remarks:

  • Do not use %-operators successively, as they only work as expected if input/output are in separate cells.
  • You don't have to define A with SetDelayed, as it is constant.
  • Use options for the Plot to set size and padding.
  • Take the first solution (there is only one, but is wrapped in list), and do a multiple replacement for the $c_i$.
  • Easiest is to put the whole Solve code in a Manipulate, as not just the plot, but the solution itself is dependent on the $T_i$.

Here is the ciorrected code:

A = 3.8*10^-3 ({{-6, 1, 1, 4}, {1, -4, 1, 2}, {1, 1, -4, 2}, {0, 0, 0, 0}});
EVe = Eigenvectors[A];
EVa = Eigenvalues[A];

Manipulate[
 sol = First@Solve[
    EVe[[1, 1]] c1 + EVe[[2, 1]] c2 + EVe[[3, 1]] c3 + EVe[[4, 1]] c4 == T1 && 
    EVe[[1, 2]] c1 + EVe[[2, 2]] c2 + EVe[[3, 2]] c3 + EVe[[4, 2]] c4 == T2 && 
    EVe[[1, 3]] c1 + EVe[[2, 3]] c2 + EVe[[3, 3]] c3 + EVe[[4, 3]] c4 == T3 && 
    EVe[[1, 4]] c1 + EVe[[2, 4]] c2 + EVe[[3, 4]] c3 + EVe[[4, 4]] c4 == T4,
    {c1, c2, c3, c4}];
 {cc1, cc2, cc3, cc4} = {c1, c2, c3, c4} /. sol;
 Plot[{cc1*EVe[[1, 1]]*E^(EVa[[1]] t) + cc2*EVe[[2, 1]]*E^(EVa[[2]] t) +
       cc3*EVe[[3, 1]] E^(EVa[[3]] t) + cc4*EVe[[4, 1]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 2]]*E^(EVa[[1]] t) + cc2*EVe[[2, 2]]*E^(EVa[[2]] t) + 
       cc3*EVe[[3, 2]] E^(EVa[[3]] t) + cc4*EVe[[4, 2]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 3]]*E^(EVa[[1]] t) + cc2*EVe[[2, 3]]*E^(EVa[[2]] t) + 
       cc3*EVe[[3, 3]] E^(EVa[[3]] t) + cc4*EVe[[4, 3]] E^(EVa[[4]] t), 
       cc1*EVe[[1, 4]]*E^(EVa[[1]] t) + cc2*EVe[[2, 4]]*E^(EVa[[2]] t) + 
       cc3*EVe[[3, 4]] E^(EVa[[3]] t) + cc4*EVe[[4, 4]] E^(EVa[[4]] t)},
      {t, 0, 500},
      PlotRange -> All, ImageSize -> 400, ImagePadding -> 20, PlotStyle -> Thick],

 {{T1, 1}, 0, 30},
 {{T2, 9}, 0, 30},
 {{T3, 1}, 0, 30},
 {{T4, 15}, 0, 30}
 ]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.