Community RSS Feed
https://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Mathematica sorted by activeHelping Mathematica to recognize the norm of a vector (Assumptions?)
https://community.wolfram.com/groups/-/m/t/1688648
Hi,
in my recent calculations for theoretical physics homework I have to do some bigger matrix multiplikations. It would be nice if Mathematice could recognise for example `Sqrt[b1^2+b2^2+b3^2]` as the norm of my vector `B` or some other name I gave it an advance.
I tried working with Assumptions and (Full-)Simplify but it didn't help in any way.
Thank you for some help!
NicolaiNicolai Anger2019-05-22T18:36:33ZAchieve a proper display of WSM-Diagrams in Mathematica?
https://community.wolfram.com/groups/-/m/t/1686643
Hi everyone,
I just noted that the icons for some components I have created are not properly visualized when having them displayed in Mathematica using `SytemModel["model"]["Diagram"]`. Here is a very short minimal example for the behavior:
model DemoIconDisplay
partial model UnidirectionalFlow "Icon for unidirectional flow classes"
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(visible = true, lineColor = {0, 128, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-100, -100}, {100, 100}}), Rectangle(visible = true, lineColor = {0, 128, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-100, -100}, {100, 100}}), Line(visible = true, origin = {-2.596, -11.973}, points = {{-72.3, 0}, {72.3, 0}}, color = {0, 128, 0}, thickness = 5), Line(visible = true, origin = {-1.216, 11.777}, points = {{-73.637, 0}, {73.637, 0}}, color = {0, 128, 0}, thickness = 5), Polygon(visible = true, origin = {72.114, -0.25}, rotation = -450, lineColor = {0, 128, 0}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, points = {{-22.295, -7.943}, {22.191, -7.943}, {0.104, 15.886}}), Text(visible = true, origin = {-73.452, 37.479}, textColor = {0, 128, 0}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "A"), Text(visible = true, origin = {73.452, -43.134}, textColor = {0, 128, 0}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "B"), Ellipse(visible = true, origin = {1.899, 0}, lineColor = {0, 128, 0}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15.107, -15.107}, {15.107, 15.107}}), Text(visible = true, origin = {2.487, 1}, textColor = {255, 255, 255}, extent = {{-16.513, -12.307}, {16.513, 12.307}}, textString = "X", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end UnidirectionalFlow;
partial model Interaction "Icon for interactional flow classes"
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(visible = true, lineColor = {0, 128, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-100, -100}, {100, 100}}), Line(visible = true, origin = {-1.596, -11.973}, points = {{-71, 0}, {71, 0}}, color = {0, 128, 0}, thickness = 5), Line(visible = true, origin = {-0.216, 11.777}, points = {{-73, 0}, {73, 0}}, color = {0, 128, 0}, thickness = 5), Polygon(visible = true, origin = {72.114, -0.25}, rotation = -450, lineColor = {0, 128, 0}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, points = {{-22.295, -7.943}, {22.191, -7.943}, {0.104, 15.886}}), Text(visible = true, origin = {-73.452, 37.479}, textColor = {0, 128, 0}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "A"), Text(visible = true, origin = {73.452, -43.134}, textColor = {0, 128, 0}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "B"), Polygon(visible = true, origin = {-72.424, 0}, rotation = 450, lineColor = {0, 128, 0}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, points = {{22.295, -7.943}, {-22.191, -7.943}, {-0.104, 15.886}}), Rectangle(visible = true, origin = {40.723, 0.173}, lineColor = {0, 128, 0}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, extent = {{-26.573, -12.251}, {26.573, 12.251}}), Ellipse(visible = true, origin = {1.899, 0}, lineColor = {255, 255, 255}, fillColor = {0, 128, 0}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15.107, -15.107}, {15.107, 15.107}}), Text(visible = true, origin = {2.487, 0}, textColor = {255, 255, 255}, extent = {{-16.513, -12.307}, {16.513, 12.307}}, textString = "X", textStyle = {TextStyle.Bold}), Text(visible = true, origin = {74.452, -0.51}, textColor = {255, 255, 255}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "+", fontSize = 72), Text(visible = true, origin = {-74.548, -0.51}, textColor = {255, 255, 255}, extent = {{-13.452, -20}, {13.452, 20}}, textString = "+", fontSize = 72)}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end Interaction;
replaceable Interaction interaction1 annotation(Placement(visible = true, transformation(origin = {-30, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
replaceable UnidirectionalFlow unidirectionalFlow1 annotation(Placement(visible = true, transformation(origin = {10, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
annotation(Diagram(coordinateSystem(extent = {{-150, -90}, {150, 90}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(visible = true, lineColor = {0, 114, 195}, fillColor = {255, 255, 255}, extent = {{-100, -100}, {100, 100}}, radius = 25), Text(visible = true, textColor = {64, 64, 64}, extent = {{-150, 110}, {150, 150}}, textString = "%name")}));
end DemoIconDisplay;
Now in a Mathematica notebook I can read in the model or enter it as a string (escaping the quotes and backlashes to appear verbatim) `model = ImportString[ " <paste code here> ", "mo" ]`.
model = SystemModel["DemoIconDisplay"] (* or model = ImportString[ " <paste code here> ", "mo" ] *)
![ModelRepresentation][1]
The model representation already does not look too good being very coarsely rendered. Let's look at the individual components' icons:
Through[ model["Children"]["ModelicaIcon"] ]
![IconView][2]
That is exactly how the components' icons look in System Model and in System Modeler Diagrams (using Version 12.0). All is nice and crisp.
But now, let's have a look at a model diagram, where the partial models have been instantiated. Again, in Mathematica, we do:
model["Diagram"]
![DiagramView][3]
The display is "broken" and looks rather ugly. Unfortunately, there are even worse examples.
What can be done about this?
Regards,
Guido
EDIT:
While the above is a minimal example, I feel like giving more explicit examples to demonstrate, that the display of diagrams (i.e. `SystemModel["model"]["Diagram"]` ) in its present form is rather completely useless:
Example1 (WSM Model Center):
![Example1_Original][4]
Example1 (Mathematica):
![Example1][5]
Example2 (WSM Model Center):
![Example2_Original][6]
Example2 (Mathematica):
![Example2][7]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=model.PNG&userId=566944
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=IconView.PNG&userId=566944
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=DiagramView.PNG&userId=566944
[4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Example1_Original.PNG&userId=566944
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Example1.png&userId=566944
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Example2_Original.PNG&userId=566944
[7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Example2.png&userId=566944Guido Wolf Reichert2019-05-20T09:53:03ZHow can I get to new lists?
https://community.wolfram.com/groups/-/m/t/1685871
Dear All,
How do I able to reach to new lists as follow:
![enter image description here][1]
m = {2, "*", 4, "*"}
n = {8, "*", 7, 9}
mNEW = {2, 4}
nNEW = {8, 7}
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=2202Untitled.png&userId=943918
Thank you very much.M.A. Ghorbani2019-05-19T10:58:14ZFunction Suggestions
https://community.wolfram.com/groups/-/m/t/1685310
Very interestingly Mathematica 12.0 now has some cool shorthand notations for some functions. A good example is `ReverseSortBy`.
Almost a year ago I suggest some [shorthands][1] like that if anyone is interested. One that I find myself using quite a lot is `TallySortByFirst`.
I hope Mathematica can improve and increase the number of functions like that.
[1]: https://github.com/ThalesFernandes/FunctionConcatenationThales Fernandes2019-05-17T13:57:24ZIs Mathematica 11 compatible with Mac OS Mojave
https://community.wolfram.com/groups/-/m/t/1479746
any problem with Mojave before I switch to it?michel2018-09-26T02:01:06ZWriting a Book with Mathematica
https://community.wolfram.com/groups/-/m/t/1672656
#Cross-Post from [here](https://b3m2a1.github.io/writing-books-in-mathematica.html)
---
As part of a [continuing](https://b3m2a1.github.io/making-docs-with-easyide.html) [series](https://b3m2a1.github.io/making-a-website-with-easyide.html) on [my new IDE](https://b3m2a1.github.io/easyide-an-ide-for-mathematica.html) and in particular a series that has focused on publishing—e.g., docs, websites—today we're gonna look at a new little extension to EasyIDE to work with creating books/tutorials in Mathematica. Obviously making a true book in Mathematica is something of a fool's errand, given that it doesn't have the detailed layout control of LaTeX or the grammar check/toolkit of Word, but making many chapter, many chapter PDFs, notebooks, and websites is entirely reasonable. Many people have done this over the years, [myself included](https://mresources.github.io/tutorial/) . With this new IDE work, though, this becomes even easier.
## Getting Started
I won't repeat the instructions for getting started with EasyIDE altogether here, as they are in [the](https://b3m2a1.github.io/easyide-an-ide-for-mathematica.html) [previous](https://b3m2a1.github.io/making-docs-with-easyide.html) [posts](https://b3m2a1.github.io/making-a-website-with-easyide.html) . We will need to get started with our new book, though. Here's a video showing the entire process:
[![HnLuP](https://i.stack.imgur.com/HnLuP.png)](https://www.youtube.com/watch?v=p1WRvwepdvI&feature=youtu.be)
###Creating the Book Structure
The book-content layout borrows directly from my general website building structure. We're just gonna add a few more points of metadata to it. To make this process more streamlined I've included a new Authoring toolbar that you can open by going to `Window ▸ Add Toolbar` in the menus. Once you have the toolbar open you can hit `Initialize Book` to get a dialog for making the new book.
###Creating a Book Chapter
Next we need to make a chapter for our content to live under. To do this we just hit the `New Chapter` button in the bar and give our chapter a name. It's important that we do this before making a section, as every section needs a chapter.
###Creating a Book Section
This is where we'll actually write the content. To make one of these we hit `New Section` , pick a chapter to file the section under, and then provide a name for the section. The new notebook will open up and we can put whatever content we have there.
###Pulling Content of StackExchange
To create a sample book I'm gonna pull a number of answers off StackExchange, say from the [common pitfalls question](https://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/) and the [good examples](https://mathematica.stackexchange.com/questions/18/where-can-i-find-examples-of-good-mathematica-programming-practice) question. The way I'll do this is via a Markdown → Notebook converter I wrote up as a generalization of my old Markdown → XML converter.
To pull an answer we can either get its Markdown via the Edit mechanism or we can use the API. For reasons of efficiency I'm going to choose the latter. If you don't have my StackExchange service connection [ you can get it off the paclet server](https://paclets.github.io/PacletServer/serviceconnectionstackexchange.html) . Once we have that we load the connection:
$so = ServiceConnect["StackExchange"]
(*Out:*)
![post31-3058623906089846253](https://b3m2a1.github.io/img/post31-3058623906089846253.png)
I can never remember my requests or parameters, so we'll look those up:
$so@"Requests"//Select[StringContainsQ["Question"]]
(*Out:*)
{"AnswerQuestion","LinkedQuestions","MyQuestions","MyTopQuestions","MyTopQuestionTags","NoAnswerQuestions","QuestionAnswers","QuestionComments","Questions","QuestionTimeline","RelatedQuestions","RenderQuestions","UnansweredQuestions","UserQuestions","UserTopQuestions","UserTopQuestionTags"}
$so["RequestParameters", "r"->"QuestionAnswers"]
(*Out:*)
<|"Parameters"->{"id","site","page","pagesize","fromdate","todate","order","min","max","sort","filter","preview"},"Required"->{"site"}|>
Then we pull the question ID off SE:
$qid = 18393;
And finally pull our data, using a filter that returns the `"body_markdown"` field to get the Markdown out:
$filter = "!YOKGPNvvbIpDIehANcVbZ*)Cv2";
ans = $so["QuestionAnswers", "id" -> $qid, "site" -> "Mathematica",
"filter" -> $filter];
Now we can look at one of these bodies:
ans[1, "body_markdown"]//Snippet[#, 5]&
<pre><code>(*Out:*)
##What the @#%^&amp;*?! do all those funny signs mean?##
Questions frequently arise about the meaning of the basic operators, and I hope
it will prove useful to have a sort of index for them. It would be nice to have</code></pre>
Unfortunately HTML elements are baked into this so we'll need to clean out those:
ImportString["", "HTML"];
getmd[ans_, n_] :=
StringReplace[{
ent : ("&#" ~~ NumberString ~~ ";") :>
ImportString[ent, "HTML"],
"\r" -> ""
}]@
Nest[
StringReplace[System`Convert`HTMLImportDump`fromEntities],
ans[n, "body_markdown"],
2
]
We'll also define a post-processing function to insert links where necessary:
ppLinks[tag_, body_]:=
(* Automatic invokes the default post-processor *)
Automatic[tag,
Replace[body,
s_String:>
Sequence@@
StringReplace[
s,
l:("http"~~(Except[WhitespaceCharacter]..)):>
Automatic["Link", {l, StringSplit[l, "//", 2][[2]]}]
],
1]
]
And then we can turn this into a `Notebook` using BTools:
<< BTools`Web`
MarkdownToNotebook[
getmd[ans, 1],
"PostProcessor" -> ppLinks
] // CreateDocument
![post31-3108498676653567781](https://b3m2a1.github.io/img/post31-3108498676653567781.png)
There's maybe a little bit of clean up work to do (say those two `##` ) but it's a very small amount. We can then do with this `Notebook` as we will...in particular we can copy it into a section notebook.
## Making a Book
Once we've gotten enough content ported over we have three options for how to proceed. At this point, we can either make a notebook, a PDF, or a website (or all three). Each of these is also quite straightforward once we have the EasyIDE structure.
###Making a Book Notebook
This distribution mechanism allows us to compile a single Notebook that we can send to our friends and coworkers that they can click through and is chaptered and easily navigable. All we have to do for this is go to our toolbar and hit `Create Book` (if it's been some time since we updated the table of contents we probably want to hit `Create TOC` first). Once we're done we get something like this:
[![https://i.stack.imgur.com/FqHIE.png](https://i.stack.imgur.com/FqHIE.png)](https://youtu.be/drLc4dNo8SI)
###Making a PDF
We can also build a PDF with this. There is a `Create PDF` button provided that does exactly this. Admittedly, this can be a bit finnicky as the front-end can't always export a notebook to a PDF cleanly. On the other hand, this just operates by calling `Export` on the constructed book notebook, so one can always use the system-level `Print... ▸ Save as PDF` mechanism (on Mac at least).
###Making a Website
This is the most heavy-duty but most customizable distribution mechanism. All of the book/tutorial mechanisms are also designed to make it easy to create a website from them. For this we go to `Plugins ▸ SiteBuilder ▸ Build Site` and choose our build settings. I'd turn off `Generate Aggregations` as these pages are not exposed in the default theme. If you modify the theme obviously it makes sense to turn the aggregation pages back on.
After the build we get something like this:
*landing page*
![post31-7698137239929577745](https://b3m2a1.github.io/img/post31-7698137239929577745.png)
*nav menu open*
![post31-4847562609283534597](https://b3m2a1.github.io/img/post31-4847562609283534597.png)
*sample article*
![post31-4404605020778869542](https://b3m2a1.github.io/img/post31-4404605020778869542.png)
And then you can publish it wherever you like. If you'd like an easy place to publish to, I provided some info on something I set up to make that easy [here](https://b3m2a1.github.io/making-a-website-with-easyide.html#wlsitesgithubio) .b3m2a1 2019-04-30T01:33:49ZGet drawing tools in V12.0.0.0?
https://community.wolfram.com/groups/-/m/t/1684985
How to get graphics menu & Drawing tools in mathematica online version 12.0.0.0?CHITHRA Raj2019-05-17T10:52:33ZMeaning of "[EXPERIMENTAL]"?
https://community.wolfram.com/groups/-/m/t/1670556
Dear all,
the title says it already: With MM v12.0 again we see a wealth of new functions (and to me this always feels a bit like Xmas) . What strikes me is that there seem to be surprisingly many functions qualified as "[EXPERIMENTAL]". What specifically does that mean?
Regard -- HenrikHenrik Schachner2019-04-26T19:01:13ZGet W|A functionality in Mathematica?
https://community.wolfram.com/groups/-/m/t/1684481
Hi All,
If I process the following line in Wolfram Alpha
`t-test mu0=60, xbar=58.5, s=3, n=20`
I get back useful information without reference to the actual sample. Not expecting plots or tables, but is there a way to do something similar in Mathematica?
thanks,
WhiffeeWhiffee Bollenbach2019-05-16T20:38:50Z