Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Using the hint, the second initial value is obviously 21. Indeed, I don't see that the syntax allows you to call Roots(..., method= secant) or Secant without specifying a second initial value. So, I don't know what "secant method" command you are currently using. You should also lower your tolerance. Here's my worksheet:

restart:
Digits:= 18: #Close to double precision.
f:= mul(x-k, k= 1..20) - 1e-8*x^19:
r1:= Student:-NumericalAnalysis:-Roots(
     f, x= [20,21],
     method= secant,
     maxiterations= 2^10, tolerance= 10^(2-Digits)
);


#Check residual
eval(f, x=r1);
      17.9

#Compare with fsolve results.
R:= [fsolve(f, complex, fulldigits)]:
#Find fsolve root closest to r1:
Min:= infinity:
for r in R do
     m:= abs(r-r1);
     if m < Min then  r2:= r; Min:= m  end if
end do:
 
r2;
      20.2402751265279542


eval(f, x= r2);

#So, the secant method beat fsolve for accuracy!

abs(r1-r2);

Download Roots.mw

I thought that this was already answered in the past week. Your function has no discontinuities, which is obvious if you plot it. If you don't understand this, then you need to study continuity more. I'd be happy to explain it. (There is a command discont for finding discontinuities, but it says that it cannot work on this function. I think that it is confounded by the max.) Your function does however have points of nondifferentiability. Both and diff will find these without needing further prompting. These are very powerful symbolic commands.

f:= max(x^2, sqrt(abs(x))):
diff(f,x);

We'll need to take this step by step. The first thing is to correct the obvious syntax errors. You have

legend= sprintf("Total dose...

but you did not close the quotation marks.

People here would be more likely to debug your code if you used 1D input. Most of us OGs find working with 2D input very tiresome. 

Generally, the plots, if simple, are printed in the reverse order that they are listed. So, try

plots:-display([pts2, pts1, seq(p1[i], i= 3..1, -1)]);

However, this is confounded when the plots contain different types of material. The types are surfaces, curves, points, text, and axes. These types are printed in that order, and then the printing order within each type is the reverse of the order that they appear in the display. These rules apply to inline plots. Directly exported plots may be different; I'll need to research that.

It can be done using just columnwise indexing, like this:

(x,y):= 'lista[..,k]' $ k= 1..2;

or

(x,y):= seq(lista[..,k], k= 1..2);

No, your approach is not correct. Your limits of integration are wrong. [1/2 <= x*y <= 2, 1 <= x <= 3] means that the limits of integration should be [y= 1/(2*x)..2/x, x= 1..3]. The integral should be entered as

int(exp(1/(x*y))/(y^2*(x+1)^2), [y= 1/(2*x)..2/x, x= 1..3]);

Note that you should enter this using a single int to avoid an irrelevant warning message.

Note that 1/x*y is not the same as 1/(x*y). Indeed, the former is the same as y/x and the latter is the same as 1/x/y or 1/y/x. So I made it exp(1/(x*y)) because the other forms are not elementary integrals. This parentheses placement is just a guess on my part; you'll need to check it.

Maple's differential operator, D, can find the derivative of quite complicated procedurally defined functions.

f:=x->max(x^2, sqrt(abs(x))):
D(f);

eqn:= diff(y(x),x$4)-20*diff(y(x),x$3)+158*diff(y(x),x$2)-580*diff(y(x),x)+841*y(x);
eval(eqn, y(x)= x*exp(5*x)*cos(2*x));

The above returns 0, which verifies the solution.

The implicitdiff command that you gave works for me (Maple 16.02), so I wonder what version of Maple you are using. Try changing y(x) to y; that also works for me.

g:= (x,y)-> x^3+y^3=1:
implicitdiff(g(x,y), y, x);

Get second derivative:

implicitdiff(%, y, x);

 

 

string1:= cat(seq(sprintf("(%a,%a,)==", pt3[k,1], pt3[k,2]), k= 1..op([1,1], pt3)))[1..-3];

A few characters shorter and a bit more cryptic (but requiring no local variable) is

string1:= sprintf(cat("(%a,%a,)==" $ op([1,1], pt3)), convert(pt3^%T, list)[])[1..-3];

This is not available in Maple. I think that implementing it would require fundamental changes to the GUI.

The problem with you original command is that your didn't use op. Your command was

ptslist := convert([1, 1], points, listlist);

It should be

ptslist:= convert(op([1, 1], points), listlist);

A somewhat more robust command is plottools:-getdata, because it doesn't rely on the "magic numbers" [1,1]:

convert(plottools:-getdata(points, element= "curve")[-1], listlist);

You generally can't rely on a 2d plot command to give you equally spaced data, although some will with some options (such as plot(..., adaptive= false)). 3d plots are generally evenly spaced.

If you want a 3d plot, then you need three Vectors of the same length, one for the x-coordinate data, one for the y-coordinate data, and one for the z-coordinate data. Make sure that you spell Vector with a capital V, unlike in your Question, or that you use the angle-bracket Vector constructor: < 1, 2, 3 >. If you want a 2d plot, then you just need two Vectors. Since you list two independent variables [p, sec], you are specifying a 3d plot.

To combine multiple plots, I usually prefer plots:-display over plots:-multiple, although the latter is sometimes better. Regardless of which you use, you'll need to pass it valid plotting commands. (So, note that display and multiple are both "meta" plotting commands: their primary arguments need to be plotting commands, not algebraic expressions.) The usual command for plotting equations in two variables is plots:-implicitplot. However, when it works, I prefer the command algcurves[plot_real_curve]. This command only works for some polynomial equations, but it usually gives a better plot than implicitplot when both plotting commands are passed minimal options. For example, plot_real_curves doesn't require you to specify ranges for the variables.

eqns:= [x^3-4*x=y, y^3-3*y=x]:

plots:-display(map(algcurves[plot_real_curve], (lhs-rhs)~(eqns), x, y));

From that plot we can see that all the "action" is in the ranges x= -3..3, y= -4..4. This information can be used to refine the plot using implicitplot, as done by Kitonum.

If you substitute numeric values for the variables in an equation, the result is still an equation! Were you perhaps expecting a boolean value? To get such, you need to apply at least the most trivial of Maple's boolean evaluators, evalb. In this case, (assuming that your solutions are exact algebraic numbers such as provided by solve(..., explicit)) you'll also need something like evala to simplify the algebraic numbers so that their equality can be verified.

And what do you mean by "both equations get the same result"? Even if the solution is valid, why should that mean that each equation has the same result? And it is also possible that the solution is invalid and yet the substituted equations are the same. For example, if both equations evaluate to 1=0 that would be an invalid solution, yet both equations are the same. So I see no significance to "both equations get the same result".

Now if what you actually want is to verify the accuracy of the solutions, here's something that you can do:

eqns:= {x^3-4*x=y, y^3-4*y=x}:
solns1:= solve(eqns, [x,y], explicit):
for s in solns1 do evalb~(evala(subs(s, eqns))) end do;

You will get {true} for every correct solution. This is IMO an inelegant method.

A more elegant verification method begins by converting the equations to expressions presumed to be equated to 0. But I will assume that your solution technique (your alternative to my solve) requires them to be equations. So I will convert them to expression form after generating the solutions.

eqns:= {x^3-4*x=y, y^3-4*y=x}:
solns1:= solve(eqns, [x,y], explicit):
Eqns:= (lhs-rhs)~(eqns): #Convert to expression form.
remove(s-> evala(eval(Eqns, s)) = {0}, solns1);

The returned list will contain all the invalid solutions. If they are all valid, that will be the empty list. You can use simplify instead of evala if you wish.

 

 

 

First 276 277 278 279 280 281 282 Last Page 278 of 395