0
$\begingroup$

I'm trying to show how g1 and g2 changes with s1 below and want a surface plot but it the parametric3Dplot doesn't show me the result!

Clear[d1, d2, d3, d4, L, Δs, s1, s2, sp, sm, H, HT, IM, \
v, smin, smax, f, g1, g2]
d1 = 1; d2 = 2; d3 = 4; d4 = 3;
smin = -1; smax = 1; Δs = 0.1;
L = 5;
sp = {{0, 1}, {0, 0}};
sm = {{0, 0}, {1, 0}};
n = {{0, 0}, {0, 1}};
v = {{1, 0}, {0, 0}};
IM = IdentityMatrix[2];
H = 
  MatrixForm[
    {{0, E^-s1 d1, E^s1 d3, 0}, {0, -d1 - d2 - s2/2, 0, 0}, 
     {0, 0, -d3 - d4 - s2/2, 0}, {0, E^-s1 d2, E^s1 d4, -s2}}];
HT = KroneckerProduct[H, IM, IM, IM] +
   KroneckerProduct[IM, H, IM, IM] +
   KroneckerProduct[IM, IM, H, IM] +
   KroneckerProduct[IM, IM, IM, H] +
   (d1*E^-s1) KroneckerProduct[sp, IM, IM, IM, 
     v] + (d3*E^s1) KroneckerProduct[v, IM, IM, IM, 
     sp] + (d2*E^-s1) KroneckerProduct[n, IM, IM, IM, 
     sm] + (d4*E^s1) KroneckerProduct[sm, IM, IM, IM, 
 n] - (d1) KroneckerProduct[n, IM, IM, IM, 
 v] - (d3) KroneckerProduct[v, IM, IM, IM, 
 n] - (d2) KroneckerProduct[n, IM, IM, IM, 
 v] - (d4) KroneckerProduct[v, IM, IM, IM, n] - (s2/
 2) KroneckerProduct[n, IM, IM, IM, v] - (s2/2) KroneckerProduct[
 v, IM, IM, IM, n] - (s2) KroneckerProduct[n, IM, IM, IM, n];

Table[Max[Re[Eigenvalues[HT]]], {s1,smin,smax,Δs}, 
{s2,smin,smax,Δs}];
 f = ListInterpolation[%, {{smin, smax}, {smin, smax}}];
g1[s1_] = -D[f[s1, s2], {s1, 1}] /. s2 -> 0;
g2[s1_] = -D[f[s1, s2], {s2, 1}] /. s2 -> 0;
 ParametricPlot3D[{g1[s1], g2[s1]}, {s1, smin, smax}]
$\endgroup$
  • 2
    $\begingroup$ 1. Get rid of the MatrixForm - it's meant for display purposes and should not be a part of your calculation. 2. Use ParametricPlot not ParametricPlot3D $\endgroup$ – Simon Woods Feb 25 '17 at 9:57
  • $\begingroup$ @SimonWoods Now I know why it was taking time to run this code. Thx $\endgroup$ – zhk Feb 25 '17 at 10:08
  • $\begingroup$ thanx for the MatrixForm point. but again it doesn't show the result. It's just the axes $\endgroup$ – sara kaviani Feb 25 '17 at 10:30
2
$\begingroup$

In this case I think it is easier to get results with Derivative rather than D.

Clear[g1, g2]
g1 = Derivative[1][-f[#1, #2] &]

-Derivative[1, 0][f][#1, #2]&

g2 = Derivative[0, 1][-f[#1, #2] &]

-Derivative[0, 1][f][#1, #2]&

Plot3D[{g1[s1, 0], g2[s1, 0]}, {s1, smin, smax}, {s2, smin, smax},
  PlotPoints -> 50,
  ClippingStyle -> None]

plot

Update

This is an attempt to answer an issue raise by the OP in a comment.

I don't think what you are asking for in your comment is meaningful. At least, I can't understand what you are getting at. There really isn't a 2nd axis to plot g2[s1, 0] on.

Here is a way I think you might better visualize the two derivative slices.

Plot[{g1[s1, 0], g2[s1, 0]}, {s1, smin, smax}, PlotLegends -> "Expressions"]

2Dplot

On the other hand, perhaps you really want this:

Plot3D[{g1[s1, s2], g2[s1, s2]}, {s1, smin, smax}, {s2, smin, smax}, 
  PlotPoints -> 100, ClippingStyle -> None]

3Dplot 3Dplot

I admit I am really confused about what you are trying to visualize.

$\endgroup$
  • $\begingroup$ How I will know, when to use D and Derivative? $\endgroup$ – zhk Feb 25 '17 at 15:37
  • 1
    $\begingroup$ @MMM. I would recommend reading the docs for both functions thoroughly and carefully. My personal heuristic is D for expressions and Derivative for functions. With D it is easier to get tangled up in variable scoping. $\endgroup$ – m_goldberg Feb 25 '17 at 15:41
  • $\begingroup$ @m_goldberg thats alright but do you know how I can plot one of these surfaces in which one of the axes is g1 the other one is g2 and another is s1?! $\endgroup$ – sara kaviani Feb 25 '17 at 15:52
  • $\begingroup$ @m_goldberg OP is asking for something like this ParametricPlot[{g1[s1, 0], g2[s1, 0]}, {s1, smin, smax}]. $\endgroup$ – zhk Feb 25 '17 at 16:20
  • 1
    $\begingroup$ @MMM. But I can't imagine what surface that could be. I'm trying to get the OP to clarify her thoughts on the matter. $\endgroup$ – m_goldberg Feb 25 '17 at 16:36
1
$\begingroup$

Your code is taking too much time to run. So without running it, I suggest that, since g1[s1] and g2[s1] are only functions of s1, so you should use, ParametricPlot.

If s2 is not fixed then for g1[s1, s2] and g2[s1, s2], you can use ParametricPlot3D. For more details see this.

Alternatively you can do this

ParametricPlot3D[{g1[s1], g2[s1], s1}, {s1, smin, smax}]

Edit

Thanks to @SimonWoods, once MatrixForm is removed the code runs as it should be.

ParametricPlot[{g1[s1], g2[s1]}, {s1, smin, smax}]

enter image description here

ParametricPlot3D[{g1[s1], g2[s1], s1}, {s1, smin, smax}]

enter image description here

$\endgroup$
  • $\begingroup$ it doesn't either shoe the result for ParametricPlot3D and ParametricPlot. don't know why? $\endgroup$ – sara kaviani Feb 25 '17 at 10:31
  • $\begingroup$ @sarakaviani Quit your kernel and then run the code. From menu bar click Evaluation then Quit Kernel and then click on Local. $\endgroup$ – zhk Feb 25 '17 at 10:37
  • $\begingroup$ thanx I fixed it. but the problem with 3D is that it doesn't give me a surface. I need a surface $\endgroup$ – sara kaviani Feb 25 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.