acer

26362 Reputation

29 Badges

16 years, 319 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@PhD_Wallyson I imagined that you would want the curves to be colored differently, which is why I plotted using fsolve above.

But if it doesn't matter then you can get the curves with a common color quickly from the V expression (using implicitplot, as Reuben showed):

   plots:-implicitplot(V,p=0..1,x=0..18,gridrefine=3);

@mmcdara As always, you are quite welcome.

You might find this amusing.

@GPU Programmer 

I did not mean that you would call read from inside the module definition. I meant that you would utilize the $include directive inside the module definition.

I meant that the read command would be called only once, on the master source plaintext file for the module definition. The body of the module definition could then have many $include lines (ie. one per procedure, each stored in its own plaintext file).

Member dharr has illustrated it as I meant, in this Answer.

The basic idea is that the module definition is in one text file, and all its local and export procedures or submodules are $include'd from separate text files. (They might then have their own, distinct, revision control.)

I suggest not naming plaintext files with the .maple filename extension, as the Maple GUI uses that for its workbook format. I use the following convention:
   .mpl    for the plaintext file containg the module framework
   .mm    for the plaintext files containing the module members (local procedures, exports, or submodule definitions)
   .mi      for the plaintext files of anything else $include'd during the module definition (tables, re-used boilerplate, etc)

 

@mmcdara The examples in my Answer had overrideoption being passed to plots:-display, not plottools:-extrude.

And, so, these followup examples work in Maple 2015 as well.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

q := plots:-display(plottools:-disk(1, color = blue)):

## I did not show doing it this way.
#plottools:-extrude(q, 0..10, overrideoption, style=line);

plots:-display(plottools:-extrude(q, 0..10), overrideoption, style=line);

q := plots:-display(plottools:-circle(1, color = blue)):

plots:-display(plottools:-extrude(q, 0..10), overrideoption, style=line);

 

Download extrude_override2.mw

Maple's sister product, MapleSim, has an Electrical Library with AC and DC components.

It is not free, even if you already have Maple. I mention it simply because it's related. 

@Reshu Gupta What is the reason that you wait until the 3rd post in this thread to state the x-values at which you want to plot? That is unhelpful.

Ques1_ac3.mw

@Reshu Gupta You've asked that kind of question a few times recently. But so far you have not stated how you want the data stored in the Excel file (despite being asked). That is unhelpful.

You can use the plottools:-getdata command extract the data from curves in a plot, as Matrices. You can use the ExcelTools:-Export command to export all or part of Matrices to .xls files.

Here is an example. I modified the plots so that all four curves share the same 100 x-values. In the final exported .xls file there are five columns: the x-data, and then the y-data of the four curves.   Ques1_ac2.mw

If you want a different format then you'd have to describe it clearly.

@DarkMath Yes, it is a bug. I have submitted a bug report.

I think that I can provide a workaround, by code adjustment(s).

@janhardo Adjust as needed.

restart;

interface(rtablesize=20):

NewtonM:=proc(f, a, b, xinit, N, e)
   local n, x0, E, A, x1, x, T, P;
   n:=0:
   T:=unapply(x-'f'(x)/D(f)(x),x);
   x0:=xinit:
   E:=evalf(abs(f(x0)));
   A:=Matrix(1,3,[[n,x0,E]]);
   while ( E>e and n<N ) do
     n:=n+1;
     x1:=evalf(T(x0));
     E:=abs(f(x1));
     A(n+1,1):=n;
     A(n+1,2):=x1;
     A(n+1,3):=E;
     x0:=x1;
   end do:
   P:=plots:-display(
     plot(f,a..b,color=blue),
     seq(plot([[A[i,2],0],[A[i,2],f(A[i,2])],[A[i+1,2],0]],
              color=black,thickness=2),
         i=1..A[-1,1]-1));
 return A[1..n+1,..], P;
end proc:

g:=x->sin(x)-x*cos(x);

proc (x) options operator, arrow; sin(x)-x*cos(x) end proc

fsolve({g(x)= 0}, x = -1 .. 9, maxsols=10);

{x = -0.}, {x = 4.493409457}, {x = 7.725251836}

(R1,P1):=NewtonM(g,-1,1,1,100,1e-6):
R1;

Matrix(12, 3, {(1, 1) = 0, (1, 2) = 1, (1, 3) = .3011686789, (2, 1) = 1, (2, 2) = .6420926160, (2, 3) = 0.846563982e-1, (3, 1) = 2, (3, 2) = .4219380688, (3, 3) = 0.245964986e-1, (4, 1) = 3, (4, 2) = .2795939323, (4, 3) = 0.72287494e-2, (5, 1) = 4, (5, 2) = .1859066079, (5, 3) = 0.21343297e-2, (6, 1) = 5, (6, 2) = .1237944854, (6, 3) = 0.6314180e-3, (7, 1) = 6, (7, 2) = 0.8248743413e-1, (7, 3) = 0.18695910e-3, (8, 1) = 7, (8, 2) = 0.5497914160e-1, (8, 3) = 0.5537852e-4, (9, 1) = 8, (9, 2) = 0.3664906635e-1, (9, 3) = 0.1640625e-4, (10, 1) = 9, (10, 2) = 0.2443161215e-1, (10, 3) = 0.486082e-5, (11, 1) = 10, (11, 2) = 0.1628741094e-1, (11, 3) = 0.144020e-5, (12, 1) = 11, (12, 2) = 0.1085818519e-1, (12, 3) = 0.4267200000e-6})

P1;

(R2,P2):=NewtonM(g,4,6,5.5,100,1e-4):
R2;

Matrix(4, 3, {(1, 1) = 0, (1, 2) = 5.5, (1, 3) = 4.603224085, (2, 1) = 1, (2, 2) = 4.313746283, (2, 3) = .7528688100, (3, 1) = 2, (3, 2) = 4.503123428, (3, 3) = 0.426979977e-1, (4, 1) = 3, (4, 2) = 4.493430093, (4, 3) = 0.905083e-4})

(R3,P3):=NewtonM(g,4,6,5.5,100,1e-6):
R3;

Matrix(5, 3, {(1, 1) = 0, (1, 2) = 5.5, (1, 3) = 4.603224085, (2, 1) = 1, (2, 2) = 4.313746283, (2, 3) = .7528688100, (3, 1) = 2, (3, 2) = 4.503123428, (3, 3) = 0.426979977e-1, (4, 1) = 3, (4, 2) = 4.493430093, (4, 3) = 0.905083e-4, (5, 1) = 4, (5, 2) = 4.493409458, (5, 3) = 0.5000000000e-9})

P3;

(R4,P4):=NewtonM(g,6.6,8.3,7,100,1e-6):
R4;

Matrix(5, 3, {(1, 1) = 0, (1, 2) = 7, (1, 3) = 4.620329181, (2, 1) = 1, (2, 2) = 8.004658280, (2, 3) = 2.190226146, (3, 1) = 2, (3, 2) = 7.727903632, (3, 3) = 0.203232309e-1, (4, 1) = 3, (4, 2) = 7.725252741, (4, 3) = 0.69267e-5, (5, 1) = 4, (5, 2) = 7.725251837, (5, 3) = 0.3000000000e-9})

P4;

 

Download NewtM_ac.mw

note: You don't have to have the procedure return the plot. Given the returned Matrix that was assigned to R4 (for example), you can also get the plot afterwards like this:

plots:-display(plot(g,6.6..8.3,color=blue),
               seq(plot([[R4[i,2],0],[R4[i,2],g(R4[i,2])],[R4[i+1,2],0]],
                        color=black,thickness=2),i=1..R4[-1,1]-1));

@Carl Love You wrote,

T:= unapply(x - D(f)(x)/f(x), x)

But I think you made a typo there.

Upload and attach your worksheet using the green up-arrow in the Mapleprimes editor.

It looks as if you might be using the deprecated matrix, linalg, and eigenvectors instead of the newer Matrix, LinearAlgebra, and Eigenvectors.

note. I converted your Post into a Question.

@Hnx Perhaps it doesn't matter to you so much that your proposed solution will generally produce an approximation of low accuracy to that derivative.

I have deleted yet another duplicate of this question.

(To others: please don't reply to duplicates of this.)

To the questioner: please put yout followup details (minor changes to a coefficient, request for data export, etc) here, instead of in a separate Question thread.

What do you mean by "the data points"? How did you obtain this "numeric solution of [a] differential equation"? Also, presumably you meant interpolation by piecewise splines.

If these data points were obtained from dsolve(...,numeric) then there why interpolate at all, since the returned result involves procedure that can compute on-demand at arbitrary values (using their own interpolants)?

It seems key to first find out why you are interpolating from a set of data points. What are all the things that you will do with the interpolant?

So far you haven't described anything that requires interpolating from a finite set of data points. You could do better for obtaining, say, further integrals or derivatives by modifying/augmenting the original system of DEs and solving (as dharr described).

Upload and attach your worksheet using the green up-arrow in the Mapleprimes editor.

First 64 65 66 67 68 69 70 Last Page 66 of 489