1
$\begingroup$

Consider the following code:

ClearAll["Global`*"]
s0 = ParametricNDSolveValue[{A''[t] - \[Omega]^2 A[t] == 1, A[0] == 0,
    A[1] == 0}, A, {t, 0, 1}, {\[Omega]}]
A1[\[Omega]_?NumericQ][t] := s0[\[Omega]][t];

s1 = ParametricNDSolveValue[{B''[t] - \[Omega]^2 B[t] == 
    D[A1[\[Omega]][t], t], B[0] == 0, B[1] == 0}, 
  B, {t, 0, 1}, {\[Omega]}]
B1[\[Omega]_?NumericQ][t] := s1[\[Omega]][t];

Plot[B1[1][t], {t, 0, 1}]

I get the error "Dependent variables {B,A1[\[Omega]]} cannot depend on parameters {\ \[Omega]}".

How do I get rid of this error? In the second equation A1 should be a known function, not a dependent one.

$\endgroup$

1 Answer 1

3
$\begingroup$

Try this:

s0 = ParametricNDSolveValue[{A''[t] - \[Omega]^2 A[t] == 1, A[0] == 0,
     A[1] == 0}, A, {t, 0, 1}, {\[Omega]}];
s1 = ParametricNDSolveValue[{B''[t] - \[Omega]^2 B[t] == 
     D[s0[\[Omega]][t], t], B[0] == 0, B[1] == 0}, 
   B, {t, 0, 1}, {\[Omega]}];

Plot[s1[1][t], {t, 0, 1}]

enter image description here

Have fun!

$\endgroup$
2
  • 1
    $\begingroup$ Thanks! It works.... but why? Why defining the function A gave the error? $\endgroup$
    – mattiav27
    Jan 27, 2021 at 16:22
  • $\begingroup$ You defined them a bit wrong. You might have defined as A1[\[Omega]_, t_] := s0[\[Omega]][t]; B1[\[Omega]_, t_] := s1[\[Omega]][t]; and call the plot as Plot[B1[1, t], {t, 0, 1}]. This will give the same effect. But this is not necessaty, since s0 and s1 are defined as standard functions and you may use them for plotting in a standard way. $\endgroup$ Jan 27, 2021 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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