Tag Info

New answers tagged

2

Although I cannot offer anything as robust and elegant as Rojo's single pass method I find this an interesting problem, and I present a limited alternative for the interest of others. For the sake of the examples I will use a modified y expression: x = Hold[1 + 1, 2 + 2, 3 + 3]; y = Hold[foo @ bar[2], bar[1], foo[1, bar[3]]]; If our parts are always at ...


5

Here is a very simple, step-by-step way to go about solving your problem. z[t_] := {1, t^2, t^3} Norm[z[t]] Sqrt[1 + Abs[t]^4 + Abs[t]^6] Those absolute values are going to give us trouble, so lets get rid of them. You want to plot over the range 0 to 5, so we can assume t ≥ 0. nz[t_] = Simplify[Norm[z[t]], Assumptions -> t >= 0] Sqrt[1 + ...


10

You're running into two issues. We'll start with the one that is causing the messages. By default Plot avoids symbolic evaluation of your function, and uses numeric evaluation instead. For example, it may evaluate at t=1.23: D[D[z[1.23],1.23],1.23] and then D complains that 1.23 isn't a valid variable and returns D[D[{1, 1.5129, 1.8608669999999998}, ...


4

It seems you have to evaluate Return[]. Strange that there is no command-button for this action. F5 also works. http://reference.wolfram.com/mathematica/tutorial/Dialogs.html


7

The reason your original code fails is that the TreeFrom object is only formatted as Graphics object, meaning that it converted for display rather that as part of the normal evaluation sequence. You can convert to and from box form to recover your Graphics object: tf = TreeForm[a + b^2 + c^3 + d]; gr = tf // ToBoxes // ToExpression gr /. (x_Framed ...


2

Building on swish's answer, I would write nodes = Cases[Network`GraphPlot`ExprTreePlot[a + b^2 + c^3 + d], _Framed, ∞]; This has the advantage of allowing you to work with the individual node objects; for example: nodes[[2]] If want output that looks like your printed output just evaluate Column@nodes


4

From this answer Network`GraphPlot`ExprTreePlot[a+b^2+c^3+d] /. (x_Framed :> Print[x])


3

Oska nailed it in the comments before me The trick here is to evaluate the integral only once. In your code it is being evaluated once for every point. You can evaluate the following Integrate[Sin[((1 + 1/2) x)] (1/(2 Sin[(x/2)]) - 1/x), {x, 0, t}] The outcome of this is ConditionalExpression[1/2 (t + 2 Sin[t] - 2 SinIntegral[(3 t)/2]), t \[Element] ...


6

Here is one way to define such a macro: SetAttributes[withCurrent, HoldAll] withCurrent[{v:(_Symbol...)}, body_] := Replace[Hold[v], s_ :> (s = s), {1}] /. _[a___] :> With[{a}, body] withCurrent is given the HoldAll attribute to delay the evaluation of the arguments until after we have had a chance to process them. It wraps the supplied sequence ...


3

The key is to use the injection pattern. SetAttributes[WithCurrent, HoldAll] WithCurrent[list_, delayeddefs___] := With[{ls = Replace[Map[Hold, Replace[Hold@list, Hold[{x___}] :> Hold[x]], 1], Hold[x_] :> (x = x), -1]}, Hold[With[ls, delayeddefs]] /. Hold[x___Set] :> {x}] // ReleaseHold a = 1; b = 2; c = 3; WithCurrent[{a, b}, ...


1

In case you want Mathematica to suppress on the fly simplification and having slots (#) involved, you might consider using Defer: Defer@Integrate[x^# Exp[-x], {x, 0, 1}]&/@Range[2]


4

I think the most straight forward would be to use Mathematica packages and importing the definitions in that notebook using the function Get as Szabolcs mentioned in the comments. I suggest that you have a closer look at the documentation on how to set up packages in Mathematica. Th principle is quite simple to understand. Here is a small example of how ...


1

In the first notebook: Add[x0_, y0_] := Module[{x = x0, y = y0}, x + y] Save["myFunction", Add] Or put your first notebook in to C:\Documents In the second notebook: Get["myFunction"] Add[1, 2]



Top 50 recent answers are included