0
$\begingroup$

I have created the following function which calculates the equation of a curve given it's slope as a derivative and a point.

FunctionName[fnPendiente_, puntoX_, puntoY_ ] := Module[
  {factorIntegrante, funcionExacta, solucionGeneral, sol, 
   valorConstante, solucionParticularCurva },
  ClearAll["Global`*"];
  solucionGeneral = DSolve[y'[x] == fnPendiente , y[x], x];
  solucionGeneral = Flatten[solucionGeneral];
  sol[x_] = y[x] /. solucionGeneral;
  valorConstante = Solve[sol[puntoX] == puntoY, C[1]];
  solucionParticularCurva[x_] = sol[x] /. Flatten[valorConstante];
  {solucionParticularCurva[x]}
  ]

But when I call the function:

FunctionName[Sin[3 x] - y[x], 0, 0]

I keep getting the following output:

{y[x]}

Is it something that I am missing or did incorrectly?

$\endgroup$
  • 1
    $\begingroup$ Have you tried to debug it step by step? p.s. ClearAll["Global`*"]; is a really nasty side effect. $\endgroup$ – Kuba Mar 28 '18 at 21:10
  • $\begingroup$ @Kuba Yes I tried but can't seem to figure out exactly where I went wrong. I inserted the ClearAll to see if that would help but it did not. $\endgroup$ – Omari Celestine Mar 28 '18 at 21:12
  • 2
    $\begingroup$ Use DSolve[y'[x] == fnPendiente, y, x] instead. Mathematica is doing some variable renaming when you define sol that is messing up your code. $\endgroup$ – Carl Woll Mar 28 '18 at 21:12
  • $\begingroup$ @carl-wool Thx. That seems to have been the issue. Could you post it as an answer so I can accept it. $\endgroup$ – Omari Celestine Mar 28 '18 at 21:52

Your Answer

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

Browse other questions tagged or ask your own question.