-1

I am trying to plot the diagrams for the given phase constants using MATLAB, but although I have look at many web pages, there is not a similar example plotting − diagram in MATLAB. Could you please clarify me how to proceed by giving some examples regarding to this problem? Any help would really be appreciated.

Plot range: =10ℎ−10

w : Angular frequency

wc : A constant Angular frequency

Parameters for 1st: 1=0.2∗, 2=0.4∗, 3=0.6∗, 4=0.8∗ , ɛ1=1* ɛ0, μ= μ0

Parameters for 1st: a1=0.08636cm, a2=0.8636cm, a3=2.286cm, a4=29.21cm, ɛ1=1* ɛ0, μ= μ0

enter image description here

10 Rep
  • 2,217
  • 7
  • 19
  • 33
Jack
  • 1
  • 21
  • 118
  • 236
  • 1
    The classic approach in 3 points: 1- Writing an expression of B with w as a value also into wc, 2 - a FOR loop of i=1:n that stores into array w[i] = 1 and array B[i] = (the formula of B with w = w[i]), 3- plot(w,B) like every 2 variables plots y=f(x) does not work? Or did I miss something? – marcoresk Nov 06 '16 at 14:09
  • @marcoresk Many thanks for your reply. Sorry, but I have really no experience and would be very grateful if you post an example code as answer. Thanks in advance... – Jack Nov 06 '16 at 14:14
  • I thought you have a lot of experience from your reputation profile. I posted an elementary answer, try it! – marcoresk Nov 06 '16 at 14:35
  • @marcoresk I have experience with ASP.NET MVC, not MATLAB :) – Jack Nov 06 '16 at 14:57

1 Answers1

1

As the OP asked, this is a sort of Matlab code. I assume to map the plot of B with w in range [1,100] (but values can be changed) First case has wc has 3 different cases, 4 different plot of B (B1,B2, B3 and B4) will be mapped in four different colors

    %constant inizialization
    mu = 1.2566E-6;
    e = 1;
    start_f = 10000; %10 MHz start frequency range
    end_f = 10000000; %10 GHz end frequency range 
    step = 10 %plot the function every "step" Hz (ONLY INTEGER NUMBERS ALLOWED)
    k = 1;
    % function of B example: B = w*sqrt(mu*e)*sqrt(1-((wc^2)/w));

    %vectors initialization to avoid the "consider preallocation" Matlab not-critical warning
    range_f = ceil((end_f - start_f)/step) + 1;
    w = zeros(range_f);
    B1 = zeros(range_f);
    B2 = zeros(range_f);
    B3 = zeros(range_f);
    B4 = zeros(range_f);

    for i=start_f:step:end_f %from 10 MHz to 10 GHz with steps of 1 Hz
    %store i in the i-cell of vector w
      w(k) = i;
%values that need to be updated every time
      w1 = 0.2*w(i);
      w2 = 0.4*w(i); 
      w3 = 0.6*w(i);
      w4 = 0.8*w(i); 
%four different results of B
      B1(i) = w(i)*sqrt(mu*e)*sqrt(1-((w1^2)/w(i)));
      B2(i) = w(i)*sqrt(mu*e)*sqrt(1-((w2^2)/w(i)));
      B3(i) = w(i)*sqrt(mu*e)*sqrt(1-((w3^2)/w(i)));
      B4(i) = w(i)*sqrt(mu*e)*sqrt(1-((w4^2)/w(i)));

      k = k+1;
    end
%plot the 4 lines    
    plot(w,B1,'r') %red line of B1 = f(w) 
    hold on
    plot(w,B2,'g') %green line of B2 = f(w) 
    hold on
    plot(w,B3,'b') %blue line of B3 = f(w) 
    hold on
    plot(w,B4,'k') %black line of B4 = f(w) 

4 different cases have to be represented with 4 plot (in this example they have been overlayed).

The last notation can be done in the same way (you have 4 constant parameters a1, a2 etc.) that does not depends from w this time. So

  B1a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B2a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B3a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B4a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));

If some errors (due to "fast" writing) occurs to you, report them in comments and I will correct and update the code

marcoresk
  • 1,837
  • 2
  • 17
  • 29
  • *"Attempted to access w(1.1); index must be a positive integer or logical."* error is encountered. Any idea? – Jack Nov 06 '16 at 15:03
  • I also added **Plot range**, **Angular frequency** and **a constant Angular frequency** parameters to the question. Thanks in advance... – Jack Nov 06 '16 at 15:08
  • @ClintEastwood my fault, I wrote the answer "too fast". (I made a little error) Update the code with adjusted frequency range too. The others specification were implicit first and does not have effect on the code (assuming that w belongs to the range of frequencies with no other changes) – marcoresk Nov 06 '16 at 16:48
  • Thanks a lot, but there is another error for which I cannot found a solution: "The variable 'x' appears to change size on every loop iteration" for *w*, B1, B2, B3 and B4. Any idea? – Jack Nov 06 '16 at 16:55
  • @ClintEastwood This is not an error and Matlab is only warning you that you can made this thing better (but still do the work). You can solve this by adding w = zeros(end_f) before the FOR cycle (do this for B1, B2... B4 too!). It is only for internal resources optimization. I'll update the code in 5 minute – marcoresk Nov 06 '16 at 17:01
  • I updated zeros(range_f) part to zeros(range_f **,1**) due to an error and now there is another little problem again: "Attempted to access w(9.99e+06); index out of bounds because numel(w)=9990001." Any idea? Many thanks for your effort voted+ :) – Jack Nov 06 '16 at 17:41
  • @ClintEastwood I adjusted it in the code before your comment (I think that simply range_f is a great number) so after your feedback I add also the option to regulate the step, try bigger step ( like 100) if this error occurs again. – marcoresk Nov 06 '16 at 18:23
  • You rock!.. Many thanks for your remarkable effort and solving the problem. I really learn many thing from you :) Voted+ – Jack Nov 08 '16 at 07:58
  • Any idea about [Plotting Electromagnetic Wave in MATLAB?](http://stackoverflow.com/questions/40492438/plotting-electromagnetic-wave-in-matlab)? Thanks in advance. – Jack Nov 08 '16 at 17:02
  • @ClintEastwood It is harder a plot of a function of two variables. Have you tried to adapt my script in this answer, using two for cycles, one inside the other, to plot, let's say, the function with respect to t at different values of z? In this way you would not obtain a surface but a parametric group of lines. At least, plot command in Matlab and FOR structure are always the same, why use "movie" command? I showed you also how to define constant and how to construct variables (w in this case). In your last question none of this things are visible in your script. – marcoresk Nov 08 '16 at 18:17
  • This is a new question and different from this one. So, I need a solution independent from this. But unfortunately no solution for that problem :( – Jack Nov 08 '16 at 18:22
  • @ClintEastwood it is different in terms of 2 indipendent variables instead of one (as I said) but once you have understand exactly what you want to obtain (what type of plot), I think it is not different in terms of plot command, proper variable definition and "Matlab grammar" in general :) – marcoresk Nov 08 '16 at 18:29
  • In that case should I look for plotting two variable function? Any example page please? – Jack Nov 08 '16 at 18:45