How can the range of the horizontal axis be extended?

Hi, everyone! This is my first time here.
As a beginner, I really need a hand with this task.
I am attempting to extend the range of the horizontal axis, but it does not work with the option DataRange.

a = Table[x, {x, 1, 10}];
b = Table[x^2, {x, 1, 10}];
tb3 = Table[{a[[i]], b[[i]]}, {i, 10}];
L1 = List[{15, 40}];
ListPlot[{tb3, L1}, DataRange -> {1, 20}]

Then, what should I do? Please, help me out here.
Thank you in advance.

DataRange is used to re-scale the horizontal axis. If you want to extend it, use PlotRange.

tb3 = Table[{i, i^2}, {i, 10}];  (* You don't need all of the indirection you had before. *)
L1 = {{15, 40}};    (* Using List explicitly is fine, but not necessary, just use curly braces. *)
ListPlot[{tb3, L1}, PlotRange -> {{0, 20}, Automatic}]

PlotRangeDemo.bmp (309 KB)

See if this does what you want:

ListPlot[{tb3, Flatten@L1}, DataRange -> {1, 20}]

I am having to draw a curve from the solutions of a two-variable function f[jg,jf].
The FOR loop is being used to do that.

h1 = {}; For[jf = 0.001, jf <= 0.30, jf += 0.00005, s = Max[SolveValues[f2[jg, jf] == 0, jg, Reals]]; 
 AppendTo[h1, s]]; h1 // MatrixForm;
h2 = {}; For[jf = 0.001, jf <= 0.30, jf += 0.00005, s = jf;  AppendTo[h2, s]]; h2 // MatrixForm;
n1 = Length[h1]; n2 = Length[h2]; (*n1=n2*)
tb1 = Table[{h1[[i]], h2[[i]]}, {i, n1}];

Is there a better way to determine this big list of pairs {jg,jf} that describes the curve?
Please, help me out with this task.
Thank you in advance.

How does this relate to your original question?

Apparently, there is no relation, but you may have seen that I am trying to make pairs with this syntax:

tb1 = Table[{h1[[i]], h2[[i]]}, {i, n1}];

It seems too lengthy for processing, doesn’t it?
Thank you for your message.

Thank you. I really learned from your post.

Let’s examine your Table expression:

tb1 = Table[{h1[[i]], h2[[i]]}, {i, n1}]

So, you have two lists, h1 and h2, and you want to pair them up. There are other ways to do this that are more idiomatic to Mathematica. I’ll manufacture some lists to illustrate:

h1 = {1, 3, 5, 7};
h2 = {"a", "b", "c", "d"};
Transpose[{h1, h2}]
(* {{1, "a"}, {3, "b"}, {5, "c"}, {7, "d"}} *)

In general, you can probably find a Mathematica function that deals with the lists as lists rather by indexing into each list. There are various ways to thread through them or re-structure them or map over them or operate on them element-wise and so on and so forth.

You used For when it would be more natural to use Table (or some other table-like function, and see my other comment about replacing Table with Transpose). Let’s say can specify your sample points with an iteration expression and you want to apply a function to those points:

Table[myFunction[i], {i, 0.1, 0.3, 0.05}]
(* {myFunction[0.1], myFunction[0.15], myFunction[0.2], myFunction[0.25], myFunction[0.3]} *)

Array[myFunction, 5, {0.1, 0.3}]
(* {myFunction[0.1], myFunction[0.15], myFunction[0.2], myFunction[0.25], myFunction[0.3]} *)

Or let’s say you have the sample points in a list, then you can just map over the list:

samplePointsFromSomewhere = Range[.1, .3, .05];
myFunction /@ samplePointsFromSomewhere
(* {myFunction[0.1], myFunction[0.15], myFunction[0.2], myFunction[0.25], myFunction[0.3]} *)

Now, for the specific case of h2 where you just need to generate those sample points, you did this:

h2 = {};
For[jf = 0.001, jf <= 0.30, jf += 0.00005, s = jf; AppendTo[h2, s]];

But it would be much clearer and cleaner (and probably faster) to do this:

h2 = Range[.001, .3, .00005];

I cannot thank you enough for that, Eric Rimbey!
You are making me eager to study more Wolfram.

Eric, I am having trouble with the command Show.

curveA=LogLogPlot[functionA,domainA,PlotRange->{{xA1,xA2},{yA1,yA2}}]
curveB=LogLogPlot[functionB,domainB,PlotRange->{{xB1,xB2},{yB1,yB2}}]
L1 is a list defined as Table[{i,0.05},{i,1.5,2,0.1}]
P1=ListLogLogPlot[L1,PlotRange->All]

Then, here comes the command Show:

Show[{curveA,curveB,P1,PlotRange->All]

Unfortunately, when I change the PlotRange with Show for what I want that to be, the plot disappears.
How can I specify the range in the option PlotRange within the command Show?
Thank you once again for your kind attention.

Since I don’t have your actual functions (e.g. functionA), I can’t reproduce this.

I don’t know if this will help, but using completely different and arbitrary functions, this all seems to work for me:

curveA = Plot[Sin[x], {x, 1, 10}];
curveB = Plot[Cos[x], {x, 5, 20}];

Show[{curveA, curveB}]

SimpleShow.bmp (903 KB)

Show[{curveA, curveB}, PlotRange -> All]

ShowAll.bmp (903 KB)

Show[{curveA, curveB}, PlotRange -> {{5, 15}, {-10, 10}}]

ShowRange.bmp (937 KB)

Eric, Mathematica fascinates me as much as your good explanation!
Thank you very much.

Hi, Eric! Can you help me once again with another question, please?
How can we combine two lists with different number of elements to form a list of pair {xi,yi} and then apply a function F[xi,yi] to each pair?
Given that L1={x1,x2} and L2={y1,y2,y3}.
A possible solution can be done as follows but there must be a clever way.
The command Transpose[] cannot be used because it only combines lists of the same size.

Thread[F[L1,a]]/.a->y1

Here one list is generated L3={F[x1,y1],F[x2,y1]}.

Thread[F[L1,a]]/.a->y2

Here another list is generated L4={F[x1,y2],F[x2,y2]}

Join[L3,L4]

I searched for a clever function like MapThread, but the command requires a list of two lists with the same number of elements. So, it cannot be used for that purpose.
How would you do in this case in order to get it more easily?
Thank you in advance for your reply.

Using Outer:

L1 = {x1, x2};
L2 = {y1, y2, y3};
Outer[F, L1, L2] // Flatten

(* {F[x1,y1],F[x1,y2],F[x1,y3],F[x2,y1],F[x2,y2],F[x2,y3]} *)

Wow! That’s fabulous!
Outer + Flatten is like a miracle.
Thank you.

It depends on how you want to fill in the missing data. But first we need to determine what you’re actually wanting. When you said:

form a list of pair {xi,yi}

I assumed that you want something like Thread, meaning that elements with the same index get paired up. But I see Hans’ answer using Outer, which will do all pairs. So, which do you want (before applying the function F)?

L1 = {x1, x2};
L2 = {y1, y2, y3};

possibleResult1 = {{x1, y1}, {x2, y2}, {y3}}
possibleResult2 = {{x1, y1}, {x2, y2}, {padding, y3}} (* where we need to figure out what padding to use *)
possibleResult3 = {{x1, y1}, {x1, y2}, {x1, y3}, {x2, y1}, {x2, y2}, {x2, y3}}

Or do you want something else entirely?

In the meantime…

(* possiblity #1 *)
F /@ Flatten[{L1, L2}, {2}]
(* {F[{x1, y1}], F[{x2, y2}], F[{y3}]} *)

F @@@ Flatten[{L1, L2}, {2}]
(* {F[x1, y1], F[x2, y2], F[y3]} *)

(* Need to decide what to do with the dangling F[y3] or F[{y3}] *)


(* possibility #2 *)
F /@ Transpose[PadRight[{L1, L2}]]
(* {F[{x1, y1}], F[{x2, y2}], F[{0, y3}]} *)

F @@@ Transpose[PadRight[{L1, L2}]]
(* {F[x1, y1], F[x2, y2], F[0, y3]} *)

(* This assumes that 0 is an appropriate default. Different default can be specified. *)


(* possibility #3 *)
F /@ Tuples[{L1, L2}]
(* {F[{x1, y1}], F[{x1, y2}], F[{x1, y3}], F[{x2, y1}], F[{x2, y2}], F[{x2, y3}]} *)

F @@@ Tuples[{L1, L2}]
(* {F[x1, y1], F[x1, y2], F[x1, y3], F[x2, y1], F[x2, y2], F[x2, y3]} *)

Or, of course, Hans` answer provides another option.

Hi, Eric Rimbey and Hans Milton!
You two are contributing to keep me motivated in learning Wolfram.
Another intriguing question refers to the use of the FOR loop to find solutions (pairs {xi,yi}) for a two-variable function in the range [x0,xf], being deltax arbitrary in the FOR loop.

F[x_,y_]:= some complex (rational and ratinal-power) function involving x and y.
For fixed values of x, the values of y that satisfy the function F (or equation F==0) is determined.

w={ };For[x=x0,x<=xf,x+=deltax, s=SolveValues[F[x,y]==0,y,Reals];AppendTo[w,s]]

Actually, I found the calculation method too lengthy.
The aim is to determine the whole set of pairs {xi,yi} that represents a curve on the plot.

How could I simplify that using Wolfram functions to obtain the curve more easily?

Thank you in advance for the tips.

In general, the use of Table is more concise than using For. Example:

(* Function and loop parameters *)
F[x_,y_]:=x+10*y
x0=2;
xf=12;
deltax=3;

(* For *)
w={};
For[x=x0,x<=xf,x+=deltax,s=SolveValues[F[x,y]==0,y];AppendTo[w,s]]
w
(* {{-(1/5)}, {-(1/2)}, {-(4/5)}, {-(11/10)}} *)

(* Table *)
Table[SolveValues[F[x,y]==0,y],{x,x0,xf,deltax}]
(* {{-(1/5)}, {-(1/2)}, {-(4/5)}, {-(11/10)}} *)

Then, to get a list of x,y pairs:

Table[{x,First@SolveValues[F[x,y]==0,y]},{x,x0,xf,deltax}]
(* {{2, -(1/5)}, {5, -(1/2)}, {8, -(4/5)}, {11, -(11/10)}} *)

Hi, everyone!
I am really struggling to do something relatively simple. Please, help me out with this.
I have a list of elements Qf.
I want to test if each element of Qf belongs to an interval and then a value is given as a result, but tests are made in a sequence. Here comes what I thought the solution could be, although it failed.

nQf=Length[Qf];

Table[Which[0.06<=Qf[i]<=0.6, 0.003,0.6<Qf[i]<=8,0.04,8<Qf[i]<=40,0.2],{i,1,nQf}]

Now you are right, Hans Milton, this is completely related to my original question, but I really need a hand on this, please.
What can I do in order to get a list of elements whose values are 0.003, 0.04 and 0.2?
Thank you in advance for your response.