Page 76 -
P. 76

functions from a single script M-file and link the parameters’ values together
                             so that you only need to edit the calling script M-file. To link the values of
                             parameters to all functions in use, you can use the MATLAB global com-
                             mand. To see how this works, rewrite the above function M-files as follows:

                                function I=L1(V)
                                global R1 R                % global statement
                                Vs=5;
                                I=(Vs-V)/R1;

                                function I=L2(V)
                                global R1 R                % global statement
                                Vs=5;
                                I=V/R;

                             The calling script M-file now reads:

                                global R1 R                %global statement
                                R1=100;                    %set global resistance values
                                R=100;
                                V=0:.01:5;                 %set the voltage range
                                I1=L1(V);                  %evaluate I1
                                I2=L2(V);                  %evaluate I2
                                plot(V,I1,V,I2,'-')        %plot the two curves



                             In-Class Exercise

                             Pb. 3.6 In the above script M-file, we used arrays and the plot command.
                             Rewrite this script file such that you make use of the fplot command.



                             Further Consideration of Figure 3.1
                             Calculating the circuit values for fixed resistor values is important, but we
                             can also ask about the behavior of the circuit as we vary the resistor values.
                             Suppose we keep R  = 100Ω and V  = 5 V fixed, but vary the value that R can
                                              1            s
                             take. To this end, an analytic solution would be useful because it would give
                             us the circuit responses for a range of values of the circuit parameters R , R,
                                                                                            1
                             V . However, a plot of the lines L  and L  for different values of R can also pro-
                              s                          1     2
                             vide a great deal of qualitative information regarding how the simultaneous
                             solution to L  and L  changes as the value of R changes.
                                        1     2


                             © 2001 by CRC Press LLC
   71   72   73   74   75   76   77   78   79   80   81