# Plotting a function while varying a variable (on the x-axis) using two formulas [duplicate]

I want to plot the following function, where Rb is the variable (that has to be on the x-axis):

y[Rb]:=2*fin*(2*T*Ud - ((Ud)/(fin)) + ((Uin*Sin[2*Pi*fin*T])/(2*Pi*fin)) +
c*Rb*(2*Ud - Uin)*(Exp[-((T)/(c*Rb))] - 1))


Now Ud,fin, Uin and care constants, for example

Ud = 0.7, fin = 50, Uin = 5,  c = 470*10^(-6)


But to find T I need to solve:

FindRoot[
Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin - 2*Ud)*Exp[-T/(c*Rb)]
, {T, 1/(4*fin), 1/(2*fin)}
, WorkingPrecision -> 20
]


Now how can I plot the function y[Rb] while varying Rb?

Here is what you can do:

Define Constants:

Ud = 7/10; fin = 50; Uin = 5; c = 470*10^(-6);


Define T as a function of Rb. Call it tr[Rb]

tr[Rb_?NumericQ] :=
T /. FindRoot[
Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin - 2*Ud)*
Exp[-T/(c*Rb)], {T, 1/(4*fin), 1/(2*fin)},
WorkingPrecision -> 20]


Define y[Rb] with tr[Rb] instead of T

y[Rb_] :=
2*fin*(2*tr[Rb]*
Ud - ((Ud)/(fin)) + ((Uin*Sin[2*Pi*fin*tr[Rb]])/(2*Pi*fin)) +
c*Rb*(2*Ud - Uin)*(Exp[-((tr[Rb])/(c*Rb))] - 1))


Plot y[Rb]. Notice that you get WorkingPrecision warnings. This has to be looked into to see where the precision is getting lost.

Plot[y[Rb], {Rb, 1, 10}]


You could solve for Rb

RbT = Solve[Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin -2*Ud)*Exp[-T/(c*Rb)], Rb][[1]]
ParametricPlot[{Rb, y[Rb]} /. RbT, {T, 1/(4*fin), 1/(2*fin)},AspectRatio -> 1]


Unfortunately the Plot is empty, probably because RbT is complex!

• T follows from the equation I stated
– asd
Jun 20, 2018 at 8:26
• You gave some values for T in the FindRoot command. These values I used in the ParametricPlot... Jun 20, 2018 at 8:37
• What range Rb you expect? Jun 20, 2018 at 8:51