0
$\begingroup$

I am trying to do a manipulate with a function that depends on several variables, some of which are also functions. I can't get it to work. I have tried including an "Initialization" but it only accepts a function with a single variable. For example, if I build the following manipulate, it works:

enter image description here

However, if A now depends on two variables, "v" and "q", then it doesn't work.

enter image description here

How could I do it? Thank you very much for your help.

$\endgroup$
1
  • $\begingroup$ Please post actual, copyable input code instead of images of code! $\endgroup$
    – murray
    Dec 24, 2021 at 17:21

1 Answer 1

1
$\begingroup$

Try:

a = 2 v q;

Manipulate[Plot[f[v, q], {x, 14, 17}],
 {{v, 1}, 0.5, 9, 0.1}, {{q, 1}, 1, 15, 0.1},
 Initialization :> {f[v_, q_] = a x}]

Or simpler:

Manipulate[
 a = 2 v q;
 Plot[a x, {x, 14, 17}],
 {{v, 1}, 0.5, 9, 0.1}, {{q, 1}, 1, 15, 0.1}]
$\endgroup$
9
  • $\begingroup$ Thank you very much Daniel. And if now for example q were a function of another variable, in initizalitazion I should put all the variables. $\endgroup$
    – Manu
    Mar 29, 2021 at 9:42
  • $\begingroup$ Can you make an example? $\endgroup$ Mar 29, 2021 at 9:48
  • $\begingroup$ Now, v and q are functions of b and c, respectivelly. a = 2 v q; v = 3 + b q = 2 c; Manipulate[ Plot[f[b, c], {x, 14, 17}], {{b, 1}, 0.5, 9, 0.1}, {{c, 1}, 1, 15, 0.1}, Initialization :> {f[c_, b_] = a*x}] $\endgroup$
    – Manu
    Mar 29, 2021 at 9:54
  • $\begingroup$ 3 + b q = 2 c; is a syntax error. Do you mean: v= 2 c ? Further, if "v and q are functions of b and c" you should specify: v=.., c=.. $\endgroup$ Mar 29, 2021 at 10:52
  • $\begingroup$ Sorry, I want write that a = 2 vq; v = 3 + b; q = 2 c; a is a function of v and q. On the other hand, v is function of b and q is function of c. I have probe the code that I indicated you before and it work. $\endgroup$
    – Manu
    Mar 29, 2021 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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