I have a function like this
CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_]
Now, I want to add a new parameter
u0 = u[α_, β_, λ_]
as an optional without rewriting the function. Even I have tried
CentralDifferentMethod[α_, β_, α1_, α2_, λ_, u0:_u[α_, β_, λ_], v0_, dt_, t_]
but it does not work. Any suggestions ?
Edit
To clarify my question, I post a part of my code:
CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_]:=
Module[{sMatrix, mMatrix, dMatrix, disp, velo, accel, result, index, reff,
effStiffnessMatrix},
sMatrix = lumpingMatrix[stiffnessMatrix[α]];
mMatrix = lumpingMatrix[massMatrix[β]];
dMatrix = lumpingMatrix[dampMatrix[α1, α2]];
disp[0] = u[α, β, λ]; (*initial displacement*)
velo[0] = v0;
accel[0] = -Inverse[mMatrix].(dMatrix.velo[0] + sMatrix.disp[0]);
effStiffnessMatrix = 1/dt^2 mMatrix + 1/(2 dt) dMatrix;
For[index = 0, index < Floor[t/dt], index++,
reff =
sMatrix.disp[index] + 1/(2 dt) dMatrix.disp[index - 1] +
mMatrix.(2 disp[index] - disp[index - 1])*1/dt^2;
disp[index + 1] = reff/Diagonal[effStiffnessMatrix];
result = Insert[result, disp[index + 1]];
result]
In most cases, the default initial displacement, disp[0]
, is known to be u[α, β, λ]
. However, I sometimes want to use another initial condition, disp[0] = u0
, where U0
is an arbitrary vector given to CentralDifferentMethod
as an argument.
Any suggestions?
u[α_, β_, λ_]
is not a function. You need to include examples of the input and output of this function. As it stands you only have pseudo-code for the left-hand-side. $\endgroup$CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_, uo_] := Module{...}, ... disp[0] = u0; ...]
and then add a 2nd definitionCentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_] := CentralDifferentMethod[α, β, α1, α2, λ, v0, dt, t, u[α, β, λ]]
. $\endgroup$