Skip to main content
Post Reopened by MarcoB, Feyre, bbgodfrey, user9660, Karsten7
added 692 characters in body
Source Link
dfs
  • 21
  • 2

I have athank you for your explainations. Both of the proposed solutions:

Plot[g[x - a] - g[0] + f[a], {x, a, a+b}] by Michael E2
f3[x_] := Piecewise[{{f1[x], 0 <= x<= 5}, {f2[x - 5], 5 < x <= 20}}] by m_goldberg

look to be promising but as the real problem relatedis a little more complicated and being a newbie with the plot commandmathematica, I'll try to be more specific. In details I want to draw light propagation inside an optical system by using ABCD matrices. As an example, I needdefine three matrices m6,m7 and m8

m6 = {{1, x}, {0, 1}}; 
m7 = {{1, 0}, {-1/f, 1}}; 
m8 = {{1, ldl}, {0, 1}}; 

where x and ldl are distances and f is a fixed numerical value for a lens power.

I use these numerical values:

y0 = 10 10^-6;
t0 = 0 Pi/180;
f = 50 10^-3;
ldlt = 10 10^-2;
xt = 30 10^-2;

Then I want to plot several functions on the sametrends of y1 and y2 given by

{y1, t1} = m8.{y0, t0} 
y1t = Table[y1, {ldl, 0, ldlt, ldlt/100 }];
t1t = Table[t1, {ldl, 0, ldlt, ldlt/100 }];
{y2, t2} = m6.m7.{y1t[[101]], t1t[[101]]}. 

y1t and t1t are the last values of y0 and t0 vectors. I tried with

Show[Plot[y1, {ldl, 0, ldlt}], Plot[y2, {x, 0, xt}]] 

to plot both of them but doing like this, y2 (and for this I use the Show command….no problems herethe inclined line) but each plotwill always start from the origin must be placed exactly in correspondence toand not from the last point of the previous. Unfortunately, in calculations defining my functionsy1 (so because of the nature of0.1 in the problemattached graph) for each of these functions.

enter image description here

Then, each matrix will use a different name for the starting position must be zero. This implies that I can draw my plots together but they all have origin in zero. Is it possible to addspatial variable, so for exampleme, an extra option to force an offset just to displace the actual plot with respectx is reserved to an other? I looked for this issue in previous answers buta parameter that I could not find something similar. Justwant to give an example,optimize; I have two functions f1 and f2. I need to plot them in cascade so, f1 between [0,5] and f2 between [5,20], but f2 must be calculated20 matrices like this in [0,15]the code. The best I could obtain

So the problem is how to have bothmake each plot start from the end of them in [0,15]. I tried something like Plot[f2,{x,0+ffsetthe previous one ideally by keeping the proper spatial variable name (ldl,15+offset}] but it modifies also data in f2 x, and I don't want this at all...whatever). Thank

Thank you in advance for any help

I have a problem related with the plot command. In details, I need to plot several functions on the same plot (and for this I use the Show command….no problems here) but each plot origin must be placed exactly in correspondence to the last point of the previous. Unfortunately, in calculations defining my functions (so because of the nature of the problem) for each of these functions, the starting position must be zero. This implies that I can draw my plots together but they all have origin in zero. Is it possible to add, for example, an extra option to force an offset just to displace the actual plot with respect to an other? I looked for this issue in previous answers but I could not find something similar. Just to give an example, I have two functions f1 and f2. I need to plot them in cascade so, f1 between [0,5] and f2 between [5,20], but f2 must be calculated in [0,15]. The best I could obtain is to have both of them in [0,15]. I tried something like Plot[f2,{x,0+ffset,15+offset}] but it modifies also data in f2, and I don't want this at all.... Thank you in advance for any help

thank you for your explainations. Both of the proposed solutions:

Plot[g[x - a] - g[0] + f[a], {x, a, a+b}] by Michael E2
f3[x_] := Piecewise[{{f1[x], 0 <= x<= 5}, {f2[x - 5], 5 < x <= 20}}] by m_goldberg

look to be promising but as the real problem is a little more complicated and being a newbie with mathematica, I'll try to be more specific. I want to draw light propagation inside an optical system by using ABCD matrices. As an example, I define three matrices m6,m7 and m8

m6 = {{1, x}, {0, 1}}; 
m7 = {{1, 0}, {-1/f, 1}}; 
m8 = {{1, ldl}, {0, 1}}; 

where x and ldl are distances and f is a fixed numerical value for a lens power.

I use these numerical values:

y0 = 10 10^-6;
t0 = 0 Pi/180;
f = 50 10^-3;
ldlt = 10 10^-2;
xt = 30 10^-2;

Then I want to plot the trends of y1 and y2 given by

{y1, t1} = m8.{y0, t0} 
y1t = Table[y1, {ldl, 0, ldlt, ldlt/100 }];
t1t = Table[t1, {ldl, 0, ldlt, ldlt/100 }];
{y2, t2} = m6.m7.{y1t[[101]], t1t[[101]]}. 

y1t and t1t are the last values of y0 and t0 vectors. I tried with

Show[Plot[y1, {ldl, 0, ldlt}], Plot[y2, {x, 0, xt}]] 

to plot both of them but doing like this, y2 (the inclined line) will always start from the origin and not from the last point of y1 (0.1 in the attached graph).

enter image description here

Then, each matrix will use a different name for the spatial variable, so for me, x is reserved to a parameter that I want to optimize; I have 20 matrices like this in the code.

So the problem is how to make each plot start from the end of the previous one ideally by keeping the proper spatial variable name (ldl, x, whatever).

Thank you for any help

Post Closed as "Not suitable for this site" by m_goldberg, MarcoB, corey979, Feyre, C. E.
edited title
Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Displace the origin of a function plot with respect to another in a Show[Plot[.. schemefunction

Source Link
dfs
  • 21
  • 2

Displace the origin of a function plot with respect to another in a Show[Plot[.. scheme

I have a problem related with the plot command. In details, I need to plot several functions on the same plot (and for this I use the Show command….no problems here) but each plot origin must be placed exactly in correspondence to the last point of the previous. Unfortunately, in calculations defining my functions (so because of the nature of the problem) for each of these functions, the starting position must be zero. This implies that I can draw my plots together but they all have origin in zero. Is it possible to add, for example, an extra option to force an offset just to displace the actual plot with respect to an other? I looked for this issue in previous answers but I could not find something similar. Just to give an example, I have two functions f1 and f2. I need to plot them in cascade so, f1 between [0,5] and f2 between [5,20], but f2 must be calculated in [0,15]. The best I could obtain is to have both of them in [0,15]. I tried something like Plot[f2,{x,0+ffset,15+offset}] but it modifies also data in f2, and I don't want this at all.... Thank you in advance for any help