PDE Mathematica - wolfram-mathematica

I'm newbie with Mathematica, so probably my problem is very easy to be solved.
I want to solve a PDE:
The first problem is that the program is not substituting the values inside w[x,y] and its second derivatives, to use them as boundary conditions.
It tells me that Tag Equal in ((w1^(2,0))[x,y]==0)[x,y] is Protected
The other problem is that it gives me also another type of error:
"{NDsolve[{(w1^(0,4))[x,y]+(w1^(2,2))[x,y]+(w1^(4,0))[x,y]==0,{w1[0,y]==0,w1[5,y]==0,((w1^(2,0))[x,y]==0)[0,y]==0,((w1^(2,0))[x,y]==0)[5,y]==0},{w1[x,0]==3,w1[x,5]==3,((w1^(0,2))[x,y]==0)[x,0]==0,((w1^(0,2))[x,y]==0)[x,10]==0}},w1[x,y],{x,0,10},{y,0,5}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing."
Thank you in advance.
I made some changes.
First of all I fixed the boundary conditions because they had a problem.
Moreover I changed also the equation.
Now it still gives me the error:
"{NDsolve[{(w^(0,4))[x,y]+(w^(2,2))[x,y]+(w^(4,0))[x,y]==2,{w[0,y]==0,w[5,y]==0,chix[0,y]==0,chix[5,y]==0},{w[x,0]==0,w[x,10]==0,chiy[x,0]==0,chiy[x,10]==0}},w,{x,0,5},{y,0,10}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing."
If we succeed in fixing this problem, Mathematica should give us a non zero solution.
Thank you very much!
Rewriting it, it doesn't provide any solution. And it also gives no errors. It looks like it is not even substitutiing the boundary conditions. I decided to change them, solving in this way another kind of problem. It still doesn't work. I think that it is very strange, since if the boundary conditions were wrong it should have provided either an indeterminate condition or an impossible one. Any idea?
Thank you very much for your help!

Related

Diagramming Decision Trees

I have been a self-taught coder for a long time, and I am asking for help with a conceptual problem here. I can solve this particular issue myself, but I feel like these problems always take me too long with trial & error solutions. I believe there is a way to Diagram this type of problem, but I don't know what it is called or how to look up this solution.
When I have multiple, often inter-dependent pre-conditions to a conditional outcome like as follows, it takes me forever to figure how to arrange my conditional statements:
I have a set of Values called: "Tab Numbers". Let's say I have 4 pre-conditions:
All Tab Numbers are blank
Some Tab Numbers are blank
A Session Boolean flag called SuppressPrompt is True
This Method is being called during the Open Session Event
These Pre-conditions determine my 3 desired outcomes:
A) Prompt for User Input
B) Auto-Populate Tab Numbers
C) Do Nothing
Now some of these pre-conditions affect other possible preconditions:
Eg.: The the Flag in Condition #3 cannot be set if the method is being called in the Open Method Condition #4.
I believe there is a good way to diagram these types of problems so that I don't have to puzzle through them with Trial & Error every time. Can anyone help point me to a resource to learn how to do this easier?
I am sorry if I am not posting this in the right place, but it is a problem that I keep running into. If anyone could just help point me in the right direction, I would really appreciate it.
Your truth table may look like this:
Preconditions Outcomes
AllBlank SomeBlank SupPrompt OpenSession UserInput AutoFill Notes
T T [T] T ? ? Impossible
T T T F ? ?
...
F F F F ? ?
You will hopefully see some non obvious correlations, which will allow you to simplify your table, possibly splitting it, until you get the logical expression(s) you need

Best way to search Ruby syntax in search engine

I'd like to know what suggestions there are for Googling (or using other search engines if preferable) for Ruby syntax. I'm very new, and a substantial part of my baptism by fire comes by way of reading other people's code. Ruby in particular can be challenging this way-- it's fantastically compact and easy to read if you know how to read it, so to speak. But figuring that out can be difficult at times. It's worth it, but difficult. So, for example, let's say I encounter an expression like this:
tquery = "#{MASTER_URL}#{query_str}"
Well, apparently there's something going on with the syntax #{stuff}, but what? A variable being manipulated, it seems? If you encountered such an expression and didn't know about interpolation/substitution and have no ready access to someone to ask directly, how would you go about Googling that? That's just an example, of course, but I hope it illustrates the type of problem I'd like to address.
Also, if there are better tags to apply to this post please let me know and I will add. Thank you.
Symbolhound is pretty good for this. For example, here's the search for Ruby's #{}.
Mind, as you can see from the results, it doesn't necessarily come immediately back and tell you what the notation you searched for is named, or how it's defined, but it does return some helpful results to get you started. It's especially useful for punctuation-based syntax elements that are difficult or impossible to search for in other search engines.

Cross version line matching

I'm considering how to do automatic bug tracking and as part of that I'm wondering what is available to match source code line numbers (or more accurate numbers mapped from instruction pointers via something like addr2line) in one version of a program to the same line in another. (Assume everything is in some kind of source control and is available to my code)
The simplest approach would be to use a diff tool/lib on the files and do some math on the line number spans, however this has some limitations:
It doesn't handle cross file motion.
It might not play well with lines that get changed
It doesn't look at the information available in the intermediate versions.
It provides no way to manually patch up lines when the diff tool gets things wrong.
It's kinda clunky
Before I start diving into developing something better:
What already exists to do this?
What features do similar system have that I've not thought of?
Why do you need to do this? If you use decent source version control, you should have access to old versions of the code, you can simply provide a link to that so people can see the bug in its original place. In fact the main problem I see with this system is that the bug may have already been fixed, but your automatic line tracking code will point to a line and say there's a bug there. Seems this system would be a pain to build, and not provide a whole lot of help in practice.
My suggestion is: instead of trying to track line numbers, which as you observed can quickly get out of sync as software changes, you should decorate each assertion (or other line of interest) with a unique identifier.
Assuming you're using C, in the case of assertions, this could be as simple as changing something like assert(x == 42); to assert(("check_x", x == 42)); -- this is functionally identical, due to the semantics of the comma operator in C and the fact that a string literal will always evaluate to true.
Of course this means that you need to identify a priori those items that you wish to track. But given that there's no generally reliable way to match up source line numbers across versions (by which I mean that for any mechanism you could propose, I believe I could propose a situation in which that mechanism does the wrong thing) I would argue that this is the best you can do.
Another idea: If you're using C++, you can make use of RAII to track dynamic scopes very elegantly. Basically, you have a Track class whose constructor takes a string describing the scope and adds this to a global stack of currently active scopes. The Track destructor pops the top element off the stack. The final ingredient is a static function Track::getState(), which simply returns a list of all currently active scopes -- this can be called from an exception handler or other error-handling mechanism.

Should a method parameter name specify its unit in its name?

Of the following two options for method parameter names that have a unit as well as a value, which do you prefer and why? (I've used Java syntax, but my question would apply to most languages.)
public void move(int length)
or
public void move(int lengthInMetres)
Option (1) would seem to be sufficient, but I find that when I'm coding/typing, my IDE can indicate to me I need a length value, but I typically have to break stride and look up the method's doco to determine the units, so that I pass in the correct value (and not kilometres instead of metres for example). This can be an annoying interruption to a thought process. Option (2) alleviates this problem, but can be verbose, particularly if your unit is metresPerSecondSquared or some such. Which do you think is the best?
I would recommend making your parameter (and method) names as clear as possible, even if they become wordy. You'll be glad when you look at or use the code in 6 months time, or when someone else has to look at your code.
If you think the names are becoming too long, consider rewording them. In your example you could use parameter name int Metres that would probably be clear enough. Consider changing the method name, eg public void moveMetres(int length).
In Visual Studio, the XML comments generated when you enter 3 comment symbols above a method definition will appear in Intellisense hints when you use the method in other locations. Other IDEs may have similar functionality.
Abbreviations should be used sparingly. If absolutely necessary only use commonly known and/or relevant industry-standard abbreviations and be consistent, ie use the same abbreviation everywhere.
Take a step back. Write the code then move on to something else. Come back the next day and check to see if the names are still clear.
Peer reviews can help too. Ask someone who knows the programming language (or just thinks logically), but not the specific functionality, if your naming scheme is clear enough or to help brainstorm alternatives. They might be the poor sap who has to maintain your code in the future!
I would prefer the second approach (i.e. lengthInMeters) as it describes the input needed for the method accurately. The fact that you find it confusing to figure out the units when you are just writing the code would imply it would be much more confusing when you (or some one) looks at the same piece of code later. As regard to issue of the variable name being longer you can find ways to abbreviate it (say "mtrsPerSecondSquared").
Also in defence second approach, the book Code Complete mentions a research that indicates, effort required to debug a program was minimized when variables had names averaged to 10 to 16 characters.

Is there a way to check if a label is already defined in LaTeX?

I edited the question after David Hanak's answer (thanks btw!). He helped with the syntax, but it appears that I wasn't using the right function to begin with.
Basically what I want is to let the compiler ignore multiple definitions of a certain label and just use the first. In order to do that, I thought I'd just do something like this:
\makeatletter
\newcommand{\mylabel}[1]{
\#ifundefined{#1}{\label{#1}}{X}
}
\makeatother
This does not work though, because the first option is always chosen (it doesn't matter if the label is defined or not). I think the \#ifundefined (and the suggested \ifundefined) only work for commands and not for labels, but I don't really know much about LaTeX. Any help with this would be great! Thanks!
Much later update:
I marked David Hanak's response as the correct answer to my question, but it isn't a complete solution, although it really helped me.
The problem is, I think but I'm no specialist, that even though David's code checks to see if a label is defined, it only works when the label was defined in a previous run (i.e. is in the .aux file). If two \mylabels with the same name are defined in the same run, the second will still be defined. Also, even if you manage to work around this, it will make LaTeX use the first label that you defined chronologically, and not necessarily the first in the text.
Anyway, below is my quick and dirty solution. It uses the fact that counters do seem to be defined right away.
\newcommand{\mylabel}[1]{%
\#ifundefined{c##1}{%
\newcounter{#1}%
\setcounter{#1}{0}%
}{}%
\ifthenelse{\value{#1} > 0}{}{%
\label{#1}%
\addtocounter{#1}{1}%
}%
}
I'm not sure if it is necessary to initialize the counter to 0, as it seems like a likely default, but I couldn't find if that was the case, so I'm just being safe.
Also, this uses the 'ifthen' package, which I'm not sure is necessary.
I am also not a LaTeX expert, however after one day of trying and searching the internet the following worked for me. I have used a dummy counter to solve the problem. Hopefully this helps, apparently not many people are looking for this.
\newcommand{\mylabel}[1]{
\ifcsname c##1\endcsname%
\else%
\newcounter{#1}\label{#1}%
\fi%
}
# is a special character in LaTeX. To make your declaration syntactically correct, you'll have to add two more lines:
\makeatletter
\newcommand{\mylabel}[1]{
\#ifundefined{#1}{\label{#1}}{X}
}
\makeatother
The first line turns # into a normal letter, the last line reverses its effect.
Update: You might also want to take a look at the "plain" \ifundefined LaTeX macro.
Update 2
Okay, I did some research to figure out the answer to the real problem. The thing is that defining a label does not create a macro by that name; it prepends a "r#" to it. So try the following:
\makeatletter
\newcommand{\mylabel}[1]{
\#ifundefined{r##1}{\label{#1}}{X}
}
\makeatother
For more technical details, refer to line 3863 of latex.ltx in your LaTeX distribution (where it says \def\newlabel{\#newl#bel r}).
By Victor Eijkhout, "TeX by Topic", p.143:
\def\ifUnDefinedCs#1{\expandafter\ifx\csname#1\endcsname\relax}
This can be used to check whether a label is defined; if not, the label is printed:
\newcommand{\myautoref}[1]{\ifUnDefinedCs{r##1}{\color{magenta}\IDontKnow\{#1\}}\else\autoref{#1}\fi}

Resources