Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.6K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to define functions? (Variables are not been evaluated)

Posted 10 years ago

Hello, I am fairly new to using Mathematica and for some reason when I use one of the codes of line in the attachment, all of the variables won't compute. For example if you run the code in the attachment the Fss5 nor Fss10 line of code won't completely simplify out. Does anyone have any insight into this?

Thanks in advance!!

Attachments:
POSTED BY: Stephen Bratz
5 Replies

To get a plot, you have to give a numerical value to k and [Xi]. On a different note, since your variables apparently depend on A, you may consider making it explicit, e.g.,

\[Omega][a_] = 5 a*Pi;
Subscript[r, a_, n_] = n*\[CapitalOmega]/\[Omega][a];
Subscript[DAF, a_, n_] = 
  1/Sqrt[((1 - Subscript[r, a, n]^2)^2 + (2 \[Xi]*Subscript[r, a, 
        n])^2)];
Subscript[\[CapitalPsi], a_, n_] = 
  ArcTan[(2 \[Xi]*Subscript[r, a, n])/(1 - Subscript[r, a, n]^2)];

That will save you all those code repetitions.

POSTED BY: Gianluca Gorni
Posted 10 years ago

Here is a copy of the code..that is failing. It will only plot 1 line and it's not even the right line.

Attachments:
POSTED BY: Stephen Bratz
Posted 10 years ago

@Gianluca Gorni

So if I want to compute the Fss10 variable for five different values of w being w=5,10,20,30,40(all times pi) and plot them on the same graph, how would I go about doing that? For some reason when I try to change the w value, it will not change accordingly. I can show you the code I am trying to use if you would like.

POSTED BY: Stephen Bratz

To define a function of a parameter, you need to add an underscore to the parameter, to make it a pattern:

\[Omega] = 8.0001*Pi;
\[CapitalOmega] = 2*Pi/To;
Subscript[r, n_] = n*\[CapitalOmega]/\[Omega];
\[Xi] = 0.05;
\[Rho]st = .1;
k = Fo/\[Rho]st;
Subscript[DAF, n_] = 
  1/Sqrt[((1 - Subscript[r, n]^2)^2 + (2 \[Xi]*Subscript[r, n])^2)];
Subscript[\[CapitalPsi], n_] = 
  ArcTan[(2 \[Xi]*Subscript[r, n])/(1 - Subscript[r, n]^2)];

The plot does not work because you have not given a numeric value to the symbol To. For example, the following computes fine:

To = 1;
\[Omega] = 8.0001*Pi;
\[CapitalOmega] = 2*Pi/To;
Subscript[r, n_] = n*\[CapitalOmega]/\[Omega];
\[Xi] = 0.05;
\[Rho]st = .1;
k = Fo/\[Rho]st;
Subscript[DAF, n_] = 
  1/Sqrt[((1 - Subscript[r, n]^2)^2 + (2 \[Xi]*Subscript[r, n])^2)];
Subscript[\[CapitalPsi], n_] = 
  ArcTan[(2 \[Xi]*Subscript[r, n])/(1 - Subscript[r, n]^2)];
Subscript[F, 
  ss1] = (Fo/(3 k)) + (Subscript[DAF, n]*(4.5 Fo/(k*(n*Pi)^2))*
      Cos[(n*\[CapitalOmega]*t) - Subscript[\[CapitalPsi], n]]) /. 
   n -> 1;
Subscript[F, 
  ss5] = (Fo/(3 k)) + 
   Sum[(Subscript[DAF, n]*(4.5 Fo/(k*(n*Pi)^2))*
      Cos[(n*\[CapitalOmega]*t) - Subscript[\[CapitalPsi], n]]), {n, 
     1, 5, 1}];
Subscript[F, 
  ss10] = (Fo/(3 k)) + 
   Sum[(Subscript[DAF, n]*(4.5 Fo/(k*(n*Pi)^2))*
      Cos[(n*\[CapitalOmega]*t) - Subscript[\[CapitalPsi], n]]), {n, 
     1, 10, 1}];
Subscript[F, 
  sst] = {Subscript[F, ss1], Subscript[F, ss5], Subscript[F, ss10]};
Plot[Evaluate[Subscript[F, sst]], {t, 0, 2}, 
 AxesLabel -> {"Time(s)", "Displacement(in)"}]
POSTED BY: Gianluca Gorni
Posted 10 years ago

Thank you so much for the Underscore Hint. It fixes everything!

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