Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@Markiyan Hirnyk Both techniques give solutions that minimize the 2-norm of the residuals. Any differences there are due solely to round-off error and can be resolved by manipulating Digits. But there's also the issue of minimizing the 2-norm of the results (the C[i] values) themselves. That's what optimize is doing in this case. This system is unusual in that it's both inconsistent and there's a hyperplane of residual-minimizing solutions.

@samira moradi Suppose that Data is an n x 2 Matrix containing the data. In this case, the y data should be in the first column, and the m data should be in the second column. Then simply modify the first plot command to

plot(
     [[y, m, m= 0..2], Data], labels= ['y', m],
     style= [line, point], color= [red, black],
     symbol= point, symbolsize= 1
);

@Markiyan Hirnyk My Answer is different and better and was written without having seen your Answer. It can be expressed in a single line, and it gives the solution of minimal 2-norm.

@Markiyan Hirnyk DirectSearch has returned some very large values, although correct. LeastSquares with the optimize option provides the minimal-2-norm solution. 

@vv I saw that the usage on Arrays (of any dimension) was documented and unfortunately deleted my Reply before you Replied.

@vv I think that your usage of entries is risky if you don't include option indexorder. It may be that the entries of a Vector always come in index order, but I can't find that documented. Since it's a kernel command, we can't look at its code.

Nonetheless, vote up.

@Joe Riel Aha! I've encountered this before. The problem is the plus sign!

@J4James The value of exp(x*y) is never 0 or negative, so the surface z = exp(x*y) never intersects z = 0.

Sorry, it was just a standard English response to a "Why can't" question understood literally. I do realize that English isn't your first language, so I didn't actually think that you meant it literally. No offense meant.

The function exp(x+y+z) is never 0 or negative, so "empty plot" is correct. Try changing 0 to 1 and changing the ranges from 0..1 to -2..2.

I got -x-y + ln(C) from solve(C=exp(x+y+z), z). By the way, this shows that every level surface is a plane with normal vector <1, 1, 1>.

 

@J4James Did I say that you couldn't use implicitplot3d? You can use it. But since the level surface can be solved for z (an unusual situation), you'll usually get a more accurate plot in less time with plot3d. In this case, the level surfaces are just planes, so it doesn't make that much difference. But I have the habit of trying to switch to plot3d.

@acer I misread that bullet point. I thought that it said that the globalopts were the same as the localopts except for adaptive and sample. So, the help page isn't wrong.

@acer Hmm. My first inclination was to try to pass a view spec to draw, but upon checking ?geometry,draw I saw that it wasn't one of the supported options. So that help page is wrong. But, anyway, your way---nullifying the VIEW spec---is definitely superior. Vote up.

Surprisingly, the VIEW can't be nullfied by

draw(L1, view= [DEFAULT$2]);
Error, (in geometry:-draw) improper op or subscript selector


For those who prefer minimalist code: In the subsindets, z-> NULL can be replaced by 'NULL'. That leads to this curiousity:

subsindets(draw(L1), specfunc(VIEW), ''()'');

produces the same (correct) plot and then gives the unusually formatted error message

Plot Internal Error:unrecognised option Dag in Plot:null

@sikjw1305 

Here's a resource-usage comparison for partitioning into pairs using Iterator:-SetPartitionFixedSize and using combinat:-setpartition. The former requires some significant post-processing to get it to match the format of the latter, but as we can see below, it's worth it.

restart:

AllPairPartitions:= proc(n::And(posint,even))
local p, `n/2`:= n/2;
     {seq([seq([p[2*k-1], p[2*k]], k= 1..`n/2`)],
      p= Iterator:-SetPartitionFixedSize([2$`n/2`]))
     }
end proc:

ByCombinat:= (n::And(posint,even))-> {combinat:-setpartition([$1..n], 2)[]}:     

 

It's not really fair to count the compilation time because it only occurs the first time that the Iterator is used.

CodeTools:-Usage(AllPairPartitions(2)):

memory used=9.55MiB, alloc change=32.00MiB, cpu time=156.00ms, real time=158.00ms, gc time=0ns

CodeTools:-Usage(ByCombinat(2)):

memory used=30.49KiB, alloc change=0 bytes, cpu time=0ns, real time=2.00ms, gc time=0ns

P1:= CodeTools:-Usage(AllPairPartitions(12)):

memory used=4.49MiB, alloc change=0 bytes, cpu time=78.00ms, real time=85.00ms, gc time=0ns

P2:= CodeTools:-Usage(ByCombinat(12)):

memory used=76.65MiB, alloc change=4.00MiB, cpu time=719.00ms, real time=714.00ms, gc time=46.88ms

 

Verify that the two procedures produce the same output.

evalb(P1=P2);

true

 


Download Iterator_vs_combinat.mw

@Thomas Dean It's possible to calculate the exact values in this problem. Just remove the evalfs.

@mojtaba75 Unfortunately, those file download links don't work.

First 415 416 417 418 419 420 421 Last Page 417 of 709