# Tag Info

5

I think your problem is with the specification of the base case. You're basically trying to do the following, I think: f[n_] := f[n-1] + 1 f[5] /. f[0] -> 0 Of course, this fails because f[5] tries to evaluate completely before ReplaceAll even sees it. The solution is to specify a base case in the definition of the function: f[n_] := f[n-1] + 1 f[0] ...

1

As a recurrence: ComputePoly[{}] := 1; ComputePoly[{0}] := x1 ComputePoly[{1}] := x2 ComputePoly[l_List] := ComputePoly[l[[1 ;; 1]]]*ComputePoly[Rest@l] ComputePoly[{0, 1, 0, 1, 1, 1, 1}] (* x1^2 x2^5 *) Of course different recurrence relationships need different implementations. As you don't mention your actual one it's very difficult to provide more ...

4

According to the solution of xzczd that dealing with the calculation of $$N_{i-p,p}(u_0),B_{i-p+1,p}(u_0), \cdots, N_{i,p}(u_0)$$ I mimic this strategy to calculate all the values of Berstern basis function of degree $n$ $$\color{blue}{B_{n,0}(u_0),B_{n,1}(u_0), \cdots, B{n,n}(u_0)}$$ AllBernsteinBasis[n_, u0_] := Nest[MovingAverage[ArrayPad[#, 1], {u0, ...

7

Well, to be honest, despite I've been using Mathematica for 3 years, I'm getting more and more confused about what's functional programming, but the following solution is at least more elegant and faster than yours: searchSpan2[knots_, u0_] := First@Ordering[UnitStep[u0 - knots], 1] - 1 NonzeroBasis2[p_, u_, u0_] := With[ {i = searchSpan2[u, u0], ...

1

I removed the fd[i_, j_], and replaced it with a pure function Piecewise[{{Max[s[[#1]] - strike1, 0], #2 == ts + 1}}] & Table[fd[i, j], {i, 1, as + 2}, {j, 1, ts + 1}] is equivament to Array[fd[#1,#2] &, {as + 2, ts + 1}] recursive[as_, ts_, ds_, strike1_] := With[{s = Table[i ds, {i, 0, as + 1}]}, Array[ Piecewise[{{Max[s[[#1]] - strike1, ...

5

For the auxiliary fuction searchSpan[] , which came form the following algorithm of The NURBS Book. where $U=\{\underbrace {a,\cdots ,a}_{p+1},u_{p+1},\cdots u_{m-p-1},\underbrace {b,\cdots,b}_{p+1}\}, \quad n=m-p-1$ Here is a rule-based solution that I implemented according to The Toad's answer NonzeroBasis[{deg_, knots_}, u0_] := Module[{coeff, i, ...

0

The following is perhaps elegant but not that fast. The main problem is that your ODE is increasing in complexity at each iteration. Applying N[...] at each step helps with that but sooner or later (fatally) you'll lose precision and the thing will stop converging to the desired solution. k = 3955/100; w = 1; phi[x_] := (1/2) (1 - Sin[Pi/2 x/w]) pcw[x_] := ...

6

Please read carefully the post that Leonid referred to. Let me anyway give you some tips on your code. First, Return does work differently in Mathematica than you might would expect. You can use Return to return from functions or loops like this one Do[ If[x == 5, Return[True]], {x, 10} ] What you did is to nest it which doesn't work like you expect ...

2

This might not be entirely correct or complete but it gives an idea of a recursive descent approach. Clear[coeff]; coeff[dp_Plus, mon_, vars_] := coeff[#, mon, vars] & /@ dp coeff[dp_, Dot[], vars_] /; FreeQ[dp, Dot] && FreeQ[dp, vars] := dp coeff[a_.*dp_, mon_, vars_] /; MatchQ[dp, mon] && FreeQ[a, vars] := a coeff[dp_, _, vars_] /; ...

2

Your equations are inconsistent (what happens if $l = 0, m = 1$?) but in general you can use RecurrenceTable even if RSolve fails. The following code would, if the conditions were consistent, give a table of $a(l, m)$ for $m, l \in \{0, \dots, 10 \}$: RecurrenceTable[{a[l, m] == a[-1 + l, m] + l a[l, -1 + m], a[l, 0] == 1, a[0, m] == 0}, a, {l, 0, 10}, ...

2

I tried many methods last day, lastly, I found that the following solution can deal with this problem(I didn't know why) a = Derivative[{0, {(0) ..}}, 0, k_Integer?Positive][NBSpline] // FullForm; b = Derivative[{0, {0 ..}}, 0, k_Integer?Positive][NBSpline] // FullForm; a === b True Namely,replace NBSpline /: Derivative[{0, {0 ..}}, 0, ...

Top 50 recent answers are included