Group Abstract Group Abstract

Message Boards Message Boards

0
|
18.5K Views
|
24 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How can i use expressions from previous results?

Posted 11 years ago
POSTED BY: olayinka oyekola
24 Replies
POSTED BY: olayinka oyekola
Posted 11 years ago

I don't know -- it may be just a very small number. It could go away if Chop is used. You could set the remaining undefined variables to zero and evaluate it to get its magnitude. I suspect it is so small that it will not affect numerical results once values are substituted for the remaining variables.

POSTED BY: David Keith
Attachments:
POSTED BY: olayinka oyekola

Will do :) It just finished solving on my system too. Will start extracting expressions for each variable next.

You've been much help.

Yinka

POSTED BY: olayinka oyekola
Posted 11 years ago

Thanks, Yinka, but not necessary. It was one line in a 10th generation language. But you could cite Mathematica. ;-)

POSTED BY: David Keith

David,

You are amazing. You are going on to the acknowledgement page of my thesis :)

Thanks a lot.

Yinka

POSTED BY: olayinka oyekola
Posted 11 years ago

Oh -- and to answer your last question, I was setting your variables to 1 and evaluating the equations just for the purpose of seeing the parameters by themselves.

POSTED BY: David Keith
Posted 11 years ago

Hi Yinka,

Attached is a notebook. I did not do anything special. I just used

Timing[sol = Solve[eqns, varlist]]

And Mathematica solved the system in 27 minutes on my 4-core Z800. I notice that one variable - ue - solved to 0. The rest solved to very messy expressions.

So you wind up with a nested list of rules as the solution. The expression for any of the varialbes can be had as variableName/.First[sol] The use of First clears the outer bracket of the solution set. You might get simpler expressions using sol2 = Simplify[sol], but be prepared to wait for a long time.

These expressions for the variables could be evaluated to a numerical result by using a list of rules to define the values of the parameters.

Best,

David

Attachments:
POSTED BY: David Keith

Yes, you are right, I type set them in the text, but use simpler forms for them in the Mathematica input.

Yinka

POSTED BY: olayinka oyekola
POSTED BY: olayinka oyekola
Posted 11 years ago
Attachments:
POSTED BY: David Keith

Further, I am attaching the pdf of the model expressions that I hoped to solve using Mathematica.

The expressions that appear in the Mathematica inputs with exponents are parameters. E.g. steady state ratio (ee/ke) raised to power nue is written as (ee/ke)^nue. No variables that I intended to solve for has exponents with it.

I think by creating the model list, what you referring to is for me to do what "syms" does in MATLAB, I have attempted that by varlist={.} in the terminal_conditions.nb but I am skeptical about if that's the way to do it in Mathematica.

So, given the list in the pdf file, I am hoping to have a solution for each of the 28 variables in terms of only the remaining variables and model parameters.

Please let me know if I am making any progress. Thanks.

Yinka

Attachments:
POSTED BY: olayinka oyekola

Hi David,

I have attached a notebook with just the definitions of model expressions and the list of model variables. The task is to solve for those 28 listed variables in terms of the remaining variables (these are exogenous) and the model parameters.

I hope I have done these listings correctly.

Thanks.

Yinka

Attachments:
POSTED BY: olayinka oyekola
Posted 11 years ago

You're welcome, Yinka. When you have equations and a list of the variables post a notebook again.

--David

POSTED BY: David Keith

Thank you very much David. I will go through the code to clean it up and hopefully it starts to work.

Thanks again.

Yinka

POSTED BY: olayinka oyekola
Posted 11 years ago

Hi Yinka, I looked at terminal_conditions.nb. What I see there is 28 variables defined. They are eq1 through eq28. Each is set to an expression, not an equation. For example:

eq2 = h - HEH he - HNH hn;

When I look at Example.nb above, it appears you form equations from each of these by equating the expression to 0. But you do not actually do that in terminal_conditions.nb. Notice that in Mathematica the single = is called Set, and assigns a value to a variable. The double == asserts equality.

If this is the case, the first thing to do in terminal_conditions is to form correct equations:

In[1]:= eq2 = h - HEH he - HNH hn == 0

Out[1]= h - he HEH - hn HNH == 0

Then use those with Solve or a chain of Eliminate. I notice several things in the notebook that are of concern. First, you are using variable names beginning with capitals. This can cause problems because Mathematica uses symbol names beginning with capitals for system defined symbols, like E and I. It is better to use lower case and be safe. (However, I don't see any conflicts I recognize.) I also notice "i" is used -- if this is intended to be the imaginary unit, in Mathematica that is I with a capital.

So I think the first thing is to set the eqn to real equations. Then what is needed is a list of the variables, excluding the parameters. I notice that your variable list in the text does not correspond to what is in the Mathematica input. (And the Mathematica variable names should not contain superscripts or subscripts -- that leads to endless trouble.)

Then use Eliminate and or Solve. Here I do see some difficulty. The expressions appear to use variables both in product terms and in exponents. This can be difficult.

Best regards,

David

POSTED BY: David Keith

Hi David,

That message meant to be left on the discussion for this problem (still finding my way around both the use of mathematica and its messaging board). Anyway, it is meant to be an addendum to my post containing the attachment, "terminal_conditions.nb".

Thanks.

Yinka

POSTED BY: olayinka oyekola

In addition to the above message, I hope the attached file can help to illustrate how I've been trying to do it and how my very manual approach is creating very large document that at the later stages is then running out of memory to handle.

Attachments:
POSTED BY: olayinka oyekola
Attachments:
POSTED BY: olayinka oyekola

Thanks Paul.

POSTED BY: olayinka oyekola
Posted 11 years ago

Maybe this would help too, here is an equation.

eqn = Solve[4 x + 2 y == 28 && x > 0 && y > 0, {x, y}, 
  Integers]; p = {x, y} /. eqn

In[221]:= eqn

Out[221]= {{x -> 1, y -> 12}, {x -> 2, y -> 10}, {x -> 3, 
  y -> 8}, {x -> 4, y -> 6}, {x -> 5, y -> 4}, {x -> 6, y -> 2}}

or

In[220]:= p

Out[220]= {{1, 12}, {2, 10}, {3, 8}, {4, 6}, {5, 4}, {6, 2}}

Paul.

POSTED BY: Paul Cleary

Thank you David.

POSTED BY: olayinka oyekola

Thanks David, your answer helped me with a dynamic system I was working on.

POSTED BY: Jake Trexel
Posted 11 years ago

You can use Eliminate:

In[1]:= eqs = {x + y + z == 3, 2 x + 3 y - z == 5, x + z == 4};

In[2]:= Solve[eqs]

Out[2]= {{x -> 4, y -> -1, z -> 0}}

In[3]:= eq4 = Eliminate[eqs[[{1, 2}]], x]

Out[3]= -1 + 3 z == y

In[4]:= eq5 = Eliminate[eqs[[{2, 3}]], x]

Out[4]= -1 + z == y

In[5]:= sol1 = Solve[{eq4, eq5}]

Out[5]= {{y -> -1, z -> 0}}

In[6]:= sol2 = Solve[eqs[[1]] /. sol1]

Out[6]= {{x -> 4}}
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard