Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 306 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The zip command is used to apply a two-parameter procedure to two matched arrays (or lists) of arguments.

restart:
B:= (x,y)-> fsolve(y = (1-exp(-x*b))/(1-exp(-50*b)), b):
X:= #Some array of x values
Y:= #Some array of corresponding y values
zip(B, X, Y);

Bisection is a method of last resort. Why do you want to use it? You can quickly get any number of roots of f(p) with RootFinding:-NextZero. After making Preben's unapply correction, do this:

N:= 100:  #Number of roots desired.
Root:= Array(1..N):
Root[1]:= -RootFinding:-NextZero(p-> f(-p), 0):
for n to N-1 do
     Root[n+1]:= -RootFinding:-NextZero(p-> f(-p), -Root[n])
end do:

The minus signs are because it seems that you want the roots in the negative direction.

All that you need is

series(y(x+h) - y(x-h), h=0, 3);

NumberToList:= proc(x::realcons)
uses S= StringTools;
     parse~(S:-Explode(S:-Select(S:-IsDigit, sprintf("%a", x))))
end proc:

Change the last line of your last for loop from

theta[ii](tau):=rhs(%);

to

theta[ii](tau):= value(rhs(%));

The value command makes Maple perform the integrations.

Since the desired simplification is not generally true for all bases, you have to use the symbolic option to simplify:

simplify(%, symbolic);

 

Using Maple 17, when I use solve followed by evalf, I get

Try doing a restart, then try the solve and evalf again.

A real answer can be obtained with fsolve or RootFinding:-NextZero in addition to the method that you mentioned.

KernelDensityPlot is a command in the Statistics package that will output the same plot in the normal inline manner:

Statistics:-KernelDensityPlot(Cdata);

AB,C:= LinearAlgebra:-GenerateMatrix(
     [F[k] $ k= 0..3],
     [u[k,n] $ k= 0..3, u[k,n-1] $ k= 0..3],
     augmented= false
);
A:= AB[.., 1..4];  B:= AB[.., 5..8];

1. In most cases, you reduce the error by increasing the value of Digits, which has the default value 10.

Digits:= 15:
fsolve(eqs2);

2. To get an exact solution to a decimal problem (if it's possible), use convert(..., rational):

solve(convert(eqs2, rational));

The midpoint method is not implemented in dsolve(..., numeric, method= classical[...]), so you'll have to write your own. Here's my ad hoc version---tailored to this specific problem. As you can see, the error plot is a straight (in log-log mode) line with a slope of nearly exactly 2.

 

restart:

Digits:= 15:

f:= (t,y)-> I*y:

Exact:= unapply(rhs(dsolve({diff(y(t),t) = f(t,y(t)), y(0)= -I})), t);

proc (t) options operator, arrow; -I*exp(I*t) end proc

(1)

Mid:= proc(h::{positive, realcons})
local
     y0:= -I,
     t,
     y1:= evalf(y0+h/2*(f(0,y0)+f(h, y0+h*f(0,y0)))), #one step of Heun
     y2
;
     []; #Force evalhf failure.
     for t from h by h to 1 do
          y2:= y0 + 2*h*f(t,y1);
          y0:= y1;
          y1:= y2
     end do;
     #Return the error
     evalf(abs(Exact(1)-y0))
end proc:
          

plot([seq([10^k, Mid(10^k)], k= -5..-1)], axis= [mode= log], labels= [h, `error`]);

 

 

Download Midpoint_error.mw

You need to change cos(kz - `ωt`) to cos(k*z - omega*t). I ran the code, and everything works if you correct this expression in the three places that it occurs.

I am not sure what you mean by "the scale of plot". Do you want a logarithmic scale? Do you want to extend the range on the y-axes so that both plots have the same y-axis?

Your "final result" has three terms with dimensions of force and one term with dimensions of force/temperature. Was there an integral in your code that you expected would cancel the temperature, which is your variables alfa1 and alfa2? If so, I couldn't find it.

Kitonum wrote:

But you wrote that your method does not directly prove the uniqueness of the solutions found. And how much time require such proof?

Unique means one solution. So I would not use the word unique in this situation. We seek to prove that the two stated solutions are the complete set of solutions. When a solution is unique, my program will indeed prove it unique. (It is not absolutely guaranteed that it will always be able to complete such a proof; however, I've never seen a case with a unique solution where it failed to complete the proof.) So, to prove that the multiple solutions are the complete solution set, we add constraints so that we get proven unique solutions. If we add a complete (covers all logical possibilities) and mutally exclusive set of constraints (only one at a time, of course), and each addition produces (provably) 0 or 1 solutions, then we have all the solutions.

The additional time for my program to do the proof is about 0.02 seconds. Here it is:


restart:

read "C:/Users/Carl/desktop/logic_problems.mpl":

 

Statement of the logic problem:

Who Lives in the City?

 

lifted from

http://www.mathsisfun.com/puzzles/who-lives-in-the-city--solution.html

 

Five people are standing in a queue for plane tickets in Germany; each one has a name, an age, a favorite TV program, where they live, a hairstyle and a destination.

 

Names: Bob, Keeley, Rachael, Eilish, and Amy

TV programs: The Simpsons, Coronation Street ("Corrie"), Eastenders, Desperate Housewives, and Neighbours.

 Destinations: France, Australia, England, Africa, and Italy

 Ages: 14, 21, 46, 52, and 81

 Hairstyle: Afro, long, straight, curly, and bald

 Where they live: A town, a city, a village, a farm, and a youth hostel

 

1. The person in the middle watches Desperate Housewives.

 2. Bob is the first in the queue.

 3. The person who watches the Simpsons is next to the person who lives in a youth hostel.

 4. The person going to Africa is behind Rachael.

 5. The person who lives in a village is 52.

 6. The person who is going to Australia has straight hair.

 7. The person travelling to Africa watches Desperate Housewives.

 8. The 14-year-old is at the end of the queue.

 9. Amy watches Eastenders.

 10. The person heading to Italy has long hair.

 11. Keeley lives in a village.

 12. The 46-year-old is bald.

 13. The fourth in the queue is going to England.

 14. The people who watch Desperate Housewives and Neighbours are standing next to each other.

 15. The person who watches Coronation Street stands next to the person with an afro.

 16. A person next to Rachael has an afro.

 17. The 21-year-old lives in a youth hostel.

 18. The person who watches Corrie has long hair.

 19. The 81-year-old lives on a farm.

 20. The person who is travelling to France lives in a town.

 21. Eilish is not next to the person with straight hair.

gc():  st:= time():

Vars:= [PN, Name, TV, Dest, Ages, Hair, Lives]:

PN:= [$1..5]:

Name:= [Bob, Keeley, Rachael, Eilish, Amy]:

TV:= [Simpsons, Coronation, Eastenders, Desperate, Neighbours]:

Dest:= [Fra, Aus, Eng, Afr, Ita]:

Ages:= [14, 21, 46, 52, 81]:

Hair:= [afro, long, straight, curly , bald]:

Lives:= [town, city, village, farm, youth]:

Con1:= Desperate=3:

Con2:= Bob=1:

Con3:= NextTo(Simpsons,youth,PN):

Con4:= Succ(Afr,Rachael,PN):

Con5:= village=52:

Con6:= Aus=straight:

Con7:= Afr=Desperate:
Con8:= 14=5:

Con9:= Amy=Eastenders:

Con10:= Ita=long:

Con11:= Keeley=village:

Con12:= bald=46:

Con13:= Eng=4:

Con14:= NextTo(Desperate,Neighbours,PN):

Con15:= NextTo(Coronation,afro,PN):

Con16:= NextTo(Rachael,afro,PN):

Con17:= 21=youth:

Con18:= Coronation=long:

Con19:= 81=farm:

Con20:= Fra=town:

 

City:= LogicProblem(Vars):

with(City);

Con21:= Rel(Separated, Eilish, straight, PN, [1]):

Satisfy([Con||(1..21)]);

T1:= (time()-st)*seconds;

Warning, City is not a correctly formed package - option `package' is missing

"[[Typesetting:-mi("&!!",italic = "true",mathvariant = "italic"), Typesetting:-mi("&-",italic = "true",mathvariant = "italic"), Typesetting:-mi("&<",italic = "true",mathvariant = "italic"), Typesetting:-mi("&>",italic = "true",mathvariant = "italic"), Typesetting:-mi("&?",italic = "true",mathvariant = "italic"), Typesetting:-mi("&G",italic = "true",mathvariant = "italic"), Typesetting:-mi("&Soln",italic = "true",mathvariant = "italic"), Typesetting:-mi("AutoGuess",italic = "true",mathvariant = "italic"), Typesetting:-mi("CPV",italic = "true",mathvariant = "italic"), Typesetting:-mi("CollectStats",italic = "true",mathvariant = "italic"), Typesetting:-mi("ConstNum",italic = "true",mathvariant = "italic"), Typesetting:-mi("Consts",italic = "true",mathvariant = "italic"), Typesetting:-mi("ConstsInV",italic = "true",mathvariant = "italic"), Typesetting:-mi("DifferentBlock",italic = "true",mathvariant = "italic"), Typesetting:-mi("Equation",italic = "true",mathvariant = "italic"), Typesetting:-mi("FreeGuess",italic = "true",mathvariant = "italic"), Typesetting:-mi("GoBack",italic = "true",mathvariant = "italic"), Typesetting:-mi("Guess",italic = "true",mathvariant = "italic"), Typesetting:-mi("InternalRep",italic = "true",mathvariant = "italic"), Typesetting:-mi("IsComplete",italic = "true",mathvariant = "italic"), Typesetting:-mi("IsUnique",italic = "true",mathvariant = "italic"), Typesetting:-mi("NC",italic = "true",mathvariant = "italic"), Typesetting:-mi("NV",italic = "true",mathvariant = "italic"), Typesetting:-mi("PrintConst",italic = "true",mathvariant = "italic"), Typesetting:-mi("Quiet",italic = "true",mathvariant = "italic"), Typesetting:-mi("Reinitialize",italic = "true",mathvariant = "italic"), Typesetting:-mi("SameBlock",italic = "true",mathvariant = "italic"), Typesetting:-mi("Satisfy",italic = "true",mathvariant = "italic"), Typesetting:-mi("Separated",italic = "true",mathvariant = "italic"), Typesetting:-mi("UniquenessProof",italic = "true",mathvariant = "italic"), Typesetting:-mi("VarNum",italic = "true",mathvariant = "italic"), Typesetting:-mi("VarNumC",italic = "true",mathvariant = "italic"), Typesetting:-mi("X_O",italic = "true",mathvariant = "italic")]]"

NULL

`Multiple solutions.  Two of the possibilities:`

Matrix(5, 7, {(1, 1) = 1, (1, 2) = Bob, (1, 3) = Simpsons, (1, 4) = Aus, (1, 5) = 81, (1, 6) = straight, (1, 7) = farm, (2, 1) = 2, (2, 2) = Rachael, (2, 3) = Coronation, (2, 4) = Ita, (2, 5) = 21, (2, 6) = long, (2, 7) = youth, (3, 1) = 3, (3, 2) = Keeley, (3, 3) = Desperate, (3, 4) = Afr, (3, 5) = 52, (3, 6) = afro, (3, 7) = village, (4, 1) = 4, (4, 2) = Eilish, (4, 3) = Neighbours, (4, 4) = Eng, (4, 5) = 46, (4, 6) = bald, (4, 7) = city, (5, 1) = 5, (5, 2) = Amy, (5, 3) = Eastenders, (5, 4) = Fra, (5, 5) = 14, (5, 6) = curly, (5, 7) = town}), Matrix(5, 7, {(1, 1) = 1, (1, 2) = Bob, (1, 3) = Simpsons, (1, 4) = Fra, (1, 5) = 46, (1, 6) = bald, (1, 7) = town, (2, 1) = 2, (2, 2) = Rachael, (2, 3) = Coronation, (2, 4) = Ita, (2, 5) = 21, (2, 6) = long, (2, 7) = youth, (3, 1) = 3, (3, 2) = Eilish, (3, 3) = Desperate, (3, 4) = Afr, (3, 5) = 81, (3, 6) = afro, (3, 7) = farm, (4, 1) = 4, (4, 2) = Keeley, (4, 3) = Neighbours, (4, 4) = Eng, (4, 5) = 52, (4, 6) = curly, (4, 7) = village, (5, 1) = 5, (5, 2) = Amy, (5, 3) = Eastenders, (5, 4) = Aus, (5, 5) = 14, (5, 6) = straight, (5, 7) = city})

.109*seconds

Proving that those are the only two solutions requires a bit of ingenuity. We need to add constraints to get unique solutions. If what we add covers all the possibilities, then we're done. Here I chose a simple constraint that distinguishes the two solutons. The we'll try with the negation of that constraint.

 

Satisfy([4=46]);

Reinitialize():
Satisfy([Con||(1..21), 4<>46]);

T2:= (time()-st)*seconds;

NULL

`Unique solution:`

Matrix(5, 7, {(1, 1) = 1, (1, 2) = Bob, (1, 3) = Simpsons, (1, 4) = Aus, (1, 5) = 81, (1, 6) = straight, (1, 7) = farm, (2, 1) = 2, (2, 2) = Rachael, (2, 3) = Coronation, (2, 4) = Ita, (2, 5) = 21, (2, 6) = long, (2, 7) = youth, (3, 1) = 3, (3, 2) = Keeley, (3, 3) = Desperate, (3, 4) = Afr, (3, 5) = 52, (3, 6) = afro, (3, 7) = village, (4, 1) = 4, (4, 2) = Eilish, (4, 3) = Neighbours, (4, 4) = Eng, (4, 5) = 46, (4, 6) = bald, (4, 7) = city, (5, 1) = 5, (5, 2) = Amy, (5, 3) = Eastenders, (5, 4) = Fra, (5, 5) = 14, (5, 6) = curly, (5, 7) = town})

NULL

`Unique solution:`

Matrix(5, 7, {(1, 1) = 1, (1, 2) = Bob, (1, 3) = Simpsons, (1, 4) = Fra, (1, 5) = 46, (1, 6) = bald, (1, 7) = town, (2, 1) = 2, (2, 2) = Rachael, (2, 3) = Coronation, (2, 4) = Ita, (2, 5) = 21, (2, 6) = long, (2, 7) = youth, (3, 1) = 3, (3, 2) = Eilish, (3, 3) = Desperate, (3, 4) = Afr, (3, 5) = 81, (3, 6) = afro, (3, 7) = farm, (4, 1) = 4, (4, 2) = Keeley, (4, 3) = Neighbours, (4, 4) = Eng, (4, 5) = 52, (4, 6) = curly, (4, 7) = village, (5, 1) = 5, (5, 2) = Amy, (5, 3) = Eastenders, (5, 4) = Aus, (5, 5) = 14, (5, 6) = straight, (5, 7) = city})

.125*seconds

Since {4 = 46, 4 <> 46} is a complete and mutually exclusive set of constraints, and each case generated a unique solution, we are done proving that the original two solutions are the only solutions.

 

So, the additional time to prove that those are the only solutions was

T2-T1;

0.16e-1*seconds

 


Download City_LP.mw

Hmm. Somehow your default plot options got changed. Try this:

plot3d(x^2-y^2, x = -1 .. 1, y = -1 .. 1, style= patch);

If that shows the grid, then set the option as default by

plots:-setoptions3d(style= patch);

But I still wonder how your default got changed.

First 317 318 319 320 321 322 323 Last Page 319 of 395