mathcad adding two equations with one variable - mathcad

I checked this section for a similar question and could not locate one. It's simple one I'm guessing but I just cant figure it out.
Two equations:
3x^2 + 4x -7
and
5x^2-7x+3
(or whatever one variable equation).
How can I add them in mathcad so I get the answer 8x^2 -3x-4 ?
Thanks.
Mr Noob....

There are a couple of ways to do this, they both utilise the "Symbolic Evaluation" operator.
If you load Mathcad, define your functions as shown below.
To show the result of the addition, you need to use the "Symbolic Evaluation" operator which is located within the "Symbolic Evaluation Toolbar" as shown by this icon:

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

ECLiPSe CLP : Pause between subresults found by search/6 in ic library

(This question regards search/6.)
I was wondering if there is a way -rather than manual tracing- to pause the execution of search/6 every time a new solution for a single variable was found?
I would like to accomplish this to further investigate what is happening during search in constrained models.
For example, if you are trying to solve the classic sudoku problem, and you have written a set of constraints and a print method for your board, it can be useful to print the board after setting the constraints, but before searching, in order to evaluate the strongness of your constraints. However, once search is called to solve the sudoku, you don't really have an overview of the single results being built underneath unless you do a trace.
It would be very useful if something was possible in the likes of:
(this is just an abstract example)
% Let's imagine this is a (very poorly) constrained sudoku board
?- problem(Sudoku),constraint(Sudoku),print(Sudoku).
[[1,3,_,2,_,_,7,4,_],
[_,2,5,_,1,_,_,_,_],
[4,8,_,_,6,_,_,5,_],
[_,_,_,7,8,_,2,1,_],
[5,_,_,_,9,_,3,7,_],
[9,_,_,_,3,_,_,_,5],
[_,4,_,_,_,6,8,9,_],
[_,5,3,_,_,1,4,_,_],
[6,_,_,_,_,_,_,_,_]]
Now for the search:
?- problem(Sudoku),constraint(Sudoku),search_pause(Sudoku,BT),print(Sudoku,BT).
[[1,3,6,2,_,_,7,4,_],
[_,2,5,_,1,_,_,_,_],
[4,8,_,_,6,_,_,5,_],
[_,_,_,7,8,_,2,1,_],
[5,_,_,_,9,_,3,7,_],
[9,_,_,_,3,_,_,_,5],
[_,4,_,_,_,6,8,9,_],
[_,5,3,_,_,1,4,_,_],
[6,_,_,_,_,_,_,_,_]]
Board[1,3] = 6
Backtracks = 1
more ;
Using existing Visualization tools
Have a look at the Visualization Tools Manual. You can get the kind of matrix display you want by adding a viewable_create/2 annotation to your code, and launching a Visualisation Client from TkECLiPSe's Tools-menu.
Using your own instrumented search routine
You can replace the indomain_xxx choice methods in search/6 with a user-defined one where you can print information before and/or after propagation.
If that is not enough, you can replace the whole built-in search/6 with your own, which is not too difficult, see e.g. the ECLiPSe Tutorial chapter on tree search or my answer to this question.
Tracing using data-driven facilities
Using ECLiPSe's data-driven control facilities, you can quite easily display information when certain things happen to your variables. In the simplest case you do something on variable instantiation:
?- suspend(printf("X was instantiated to %w%n",[X]), 1, X->inst),
writeln(start), X=3, writeln(end).
start
X was instantiated to 3
end
Based on this idea, you can write code that allows you to follow labeling and propagation steps even when they happen inside a black-box search routine. See the link for details.

How to get a handle to an overriden built-in function? [duplicate]

This question already has an answer here:
How to unhide an overriden function?
(1 answer)
Closed 9 years ago.
On my Matlab path there's a custom zeros function. I want to store a handle to the built-in zeros in a variable. How can I do that?
Thought about #(varargin)builtin('zeros',varargin{:}), but this would probably slow down the operation due to the string comparison.
Also, I've noticed that it's possible to refer to diag as #numel\diag, but this doesn't seem to work with other built-in functions (zeros in particular).
Suggestion #1
% At the beginning of your script:
rmpath('C:\the\folder\containing\the\custom\zeros');
builtInZeros = #zeros;
addpath('C:\the\folder\containing\the\custom\zeros');
% Calling the custom zeros later:
a = zeros(10, 20);
% Calling the built-in zeros:
b = builtInZeros(10, 20);
Suggestion #2
Put these three lines into your startup file:
rmpath('C:\the\folder\containing\the\custom\zeros');
builtInZeros = #zeros;
addpath('C:\the\folder\containing\the\custom\zeros');
Suggestion #3
It's definitely a dangerous idea to reuse the name of a built-in function. It ruins the readability of your scripts, making them much more difficult to maintain. So if you have control over the custom zeros function, then rename it to something else. Use a name which describes how the custom version is different from the built-in one (for example, call it fastZeros if it's faster).
Well, this doesn't give you an exact answer to your question, but it could solve the problem:
I think this seems to be a good solution:
matlabcentral: How to call a shadowed function
Withn the last post:
Just stumbled upon this problem and found the following solution: For
example, I have matlab svmtrain shadowed by libsvm toolbox:
which svmtrain -all
C:\Projects\Ichilov\Misc\MVPA\libsvm-mat-3.0-1\svmtrain.mexw64
C:\Program Files\MATLAB\R2009b\toolbox\bioinfo\biolearning\svmtrain.m
% Shadowed
But I can access the original function by using str2func:
org_svmtrain = str2func([matlabroot '\toolbox\bioinfo\biolearning\svmtrain'])
and then simply calling:
org_svmtrain(training, groupnames)

Get List value from another notebook in Mathematica

I have 2 notebooks in Mathematica. I need to open nb B from nb A and get a value of some parameters (List) with known names. How can I do it without running nb B?
I think you want the functions
NotebookOpen[]
and
NotebookFind[]
but without more information about what you want to do it's difficult to be more specific than this. I'm surprised that your searches of the Mathematica documentation didn't lead you to these functions (and their relatives) already.

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