1
$\begingroup$

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

y[Uin]:=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,Rb and care constants, for example

Ud = 0.7, fin = 50, Rb = 10 , c = 150*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[Uin] while varying Uin?


My work, I programmed:

Ud = 0.7; fin = 50; Rb = 10; c = 150*10^(-6);
y[Uin_] = 
  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));
Teqn[Uin_] = 
  Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin - 2*Ud)*
    Exp[-T/(c*Rb)];
Tsol[Uin_?NumericQ] := 
 FindRoot[Teqn[Uin], {T, 1/(4*fin), 1/(2*fin)}]; ListPlot[
 Table[{Uin, y[Uin] /. Tsol[Uin]}, {Uin, 0, 10, 0.001}]]

But that produces a not correct result (it gives that y[Uin] stays $1.5$ for all Uin but that can not be possible).

$\endgroup$
1
  • $\begingroup$ You are providing two values for the Tspecification in FindRoot. Those are used as the first and second values in the iteration, in order to avoid the internal use of derivatives. Is that what you intended? Perhaps a better starting value and a search interval for T would work better to avoid the warnings returned by FindRoot in your current code. $\endgroup$ Commented Jun 19, 2018 at 20:56

1 Answer 1

2
$\begingroup$

FindRoot evidently is not finding all the values. You can set up your tables before using FindRoot.

Ud = 0.7; fin = 50; Rb = 10; c = 150*10^(-6);

Teqn[Uin_] = 
 Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin - 2*Ud)*
   Exp[-T/(c*Rb)]

Table of Uin values

TUin = Table[Uin, {Uin, 0, 10, 0.001}];

Get a table of T with FindRoot.

Ttab = Table[
   T /. FindRoot[Teqn[TUin[[i]]], {T, 1/(4*fin), 1/(2*fin)}], {i, 
    Length[TUin]}];

We get some convergence warnings because for some values of Uin, there are no roots for T in the specified range. Define y.

y := 2*fin*(2*Ttab[[i]]*
     Ud - ((Ud)/(fin)) + ((TUin[[i]]*Sin[2*Pi*fin*Ttab[[i]]])/(2*Pi*
        fin)) + c*
     Rb*(2*Ud - TUin[[i]])*(Exp[-((Ttab[[i]])/(c*Rb))] - 1));

ListPlot[Table[{TUin[[i]], y}, {i, Length[Ttab]}], PlotJoined -> True]

enter image description here

The jumpy part of the early curve is due to the failure to find roots in the specified interval. You might need to relook at your data for those values.

$\endgroup$
1
  • $\begingroup$ "there are no roots for T in the specified range": if you mean the three-value syntax for the FindRoot variable, note that it provides two starting points, not a range; you must provide four values for that. $\endgroup$ Commented Jun 19, 2018 at 20:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.