Carl Love

Carl Love

28100 Reputation

25 Badges

13 years, 105 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Rouben Rostamian 

By avoiding re-integrating, I got the time for your code down to 6.3 seconds.

restart:
st:= time():
Digits:= 4:
u:= Heaviside:
f:= t-> u(t) - u(t-2):
g:= t-> t*u(t) - (t-4)*u(t-4):
plotg:= plot(g, -10..10, color= blue):
h:= unapply(Int(f(t-q)*g(q), q= -10..t), t):
ploth:= convert(op([1,1], plot(h, -10..9)), listlist):
frames:= seq(
     plots:-display([
          plot(f(t-s), s= -10..10, color= blue),
          plot(select(xy-> xy[1] <= t, ploth), color= red, thickness= 3)
     ]), t= -7..9, 0.4
):
plots:-display(
     [plots:-display([frames], insequence), plotg],
     view= [DEFAULT, `..`((min,max)(ploth[..,2]))]
);
time()-st;

@nm Sorry, my mistake, I simply forgot about the extra 0.

The existence of so-called programmer indexing for rtables (A(0) instead of A[0]) makes this a little tricky. Whereas [x,y](0) becomes [x(0),y(0)], it doesn't work for <x,y>(0). We can get around that by mapping the prefix form of the function-application operator, `?()`.

Try,

map(`?()`, D~(map2(op, 0, x(t))), [0]) =~ 0;

or

<seq(D(x)(0)=0, x= map2(op, 0, x(t)))>;

I can get a series solution for both equations if I set n=1. I haven't gotten any other n to work.

@tomleslie I intended no disparagement of your Answer. You also found genuine and important bugs in the code.

The first line of code after the procedure definition applies subs to a variable U. But U has no value other than itself. That's why Tom Leslie's plots are not very interesting.

@still0fthenight Many responders here are happy to help students with their homework if they have shown some effort, and you have clearly shown some effort. Now how about uploading that code?

@mapleus 

Like I said in the Answer, I needed to adjust the precision control after you filled in the signum. I've done this by using the option relerr= 1e-10 in dsolve and setting Digits:= 7 before doing the fsolve. This assumes that knowing X to seven digits is sufficient for your purposes.


restart:

F:= 1:  l:= 1:  a:= 0.1:  n:= 4.5:  B:= 1.47e-11:
J_nc:= evalf(2*a*int(y^(1/n+1),y=0..a/2)):
M_f:= z-> piecewise(
     z>=0 and z<=l, F*l,
     z>l and z<=2*l, F*l-F*(z-l),
     z>2*l and z<=3*l, F*l-F*(z-l)+F*(z-2*l)
):
'M_f'(z) = M_f(x); #for display only
M_ed:= z-> z-3*l:
M_x:= z-> M_f(z)+X*M_ed(z);
eq:= diff(V(z),z$2) = B*(abs(M_x(z))/J_nc)^n*signum(M_x(z));
cond:= V(0) = 0, D(V)(0) = 0:

sol_2:= dsolve({cond, eq}, numeric, parameters= [X], relerr= 1e-10):
sol_3:= proc(X)
     sol_2(parameters= [X]);
     eval(V(z), sol_2(3*l))
end proc:

Digits:= 7:
sol_X:= fsolve(sol_3);
plot(eval(M_x(z), X= sol_X), z= 0..3*l);

M_f(z) = piecewise(0 <= x and x <= 1, 1, 1 < x and x <= 2, 2-x, 2 < x and x <= 3, 0)

M_x := proc (z) options operator, arrow; M_f(z)+X*M_ed(z) end proc

diff(diff(V(z), z), z) = 7647603.*abs(piecewise(0 <= z and z <= 1, 1, 1 < z and z <= 2, 2-z, 2 < z and z <= 3, 0)+X*(-3+z))^4.5*signum(piecewise(0 <= z and z <= 1, 1, 1 < z and z <= 2, 2-z, 2 < z and z <= 3, 0)+X*(-3+z))

.3490381

 


Download dsolve_piecewise.mw

@itsme I'd be even more careful with the cutting and pasting. I might occasionally cut and paste from a 2d output (aka prettyprinted) region to a 1D input region (the only input I use) in order to inspect the internal structure of something (although I'm more likely to use lprint(%) for that); but I would never assume that the result of doing that is equivalent to some previous input.

@maple fan I'm having some trouble following this thread. Are you saying that you doubt that cos(70) = 0.633319 to six decimal places?! Any scientific pocket calculator can tell you that that's correct. Do you doubt Kitonum's result that that value can be obtained using 122 terms of the series and 40 digits precision?

@ilia_mahan No one can help you because "simplify [expression A] according to [expression B]" doesn't mean anything in mathematical English (except possibly in the case where we assume that B is 0, but that is clearly not what you mean by it). Perhaps if you provided a few simple examples of one expression being "simplified according to" another expression, we could figure it out from there.

@Axel Vogt Surely you intended to say "any piecewise constant function" instead of "any piecewise function".

@Andriy Nothing unusual is happening for you. That's just the way 2D-Math "works"---another reason to not use it. This is why you see so many posts on MaplePrimes where plaintext code looks like a solid block with no line breaks.

@ANANDMUNAGALA If you had that procedure, why did you ask this Question?

If you could point me to a web-based discussion of the algorithm, I may be able to code it in Maple.

@ANANDMUNAGALA Please submit a Maple file, not a Word file!

First 497 498 499 500 501 502 503 Last Page 499 of 709