- If you have the symbolic toolbox, you can use piecewise() to create a formula that expresses the results conditionally, such as piecewise(y >= 0 & y <= delta, expression for v1, y > delta & y <= 1, expression for v2, value to give if y is out of range)
- If you have the symbolic toolbox, you can use heaviside to create a formula that implicitly codes the required result. (1-heaviside(y-b) * heaviside(y-a) * c expressions "value is c when y >= a and y <= b" . However if you use this, you need to be careful about the boundary conditions. See sympref('HeavisideAtOrigin')
- Provided that none of your calculations can be infinite or nan, then you can express ranges using logical expressions multipled by the desired value: (a <= y & y <= b) .* c is 0 when the condition does not hold, and c when it does. This will not work if c can be infinite when not selected. For example you cannot use (y ~= 0) * 1/y to express "0 if y is 0 and 1/y otherwise" because when y does equal 0, the 1/y will be calculated giving inf and then the 0 from the logical test, multiplied by the inf, will give nan, poluting the rest of the calculation
- Create an output vector first, and then use logical expressions to assign into it: mask = (a <= y & y <= b); output(mask) = f(y(mask)) for some function f
- Loop using if/else and doing appropriate indexing. This is not as efficient as using logical indexing (well, except when you are nearly out of memory; looping wins in that case.)
difficult in programming two velocity law into one profile
1 次查看(过去 30 天)
显示 更早的评论
actually velocity law are here depends on distance from bottom wall (y-=0)
v1 is valid from y=0 to y=delta as mentioned y1
v2 valid from y=delta to y=1 as mentioned y2
and velocity is comprised of both i.ev1 is valid from y=0 to y=delta and v2 valid from y=delta to y=1
i want to plot v againest m
errors are there pls suggerst me how to do it
gamma=0.02
lambda=[0.01:0.0045:0.1]
beta=0.01
m=lambda/gamma
y2=[0.02:0.049:1]
y1=[0.0:0.001:0.02]
y=[y1 y2]
p=y2./lambda
q=y1./lambda
s=beta./lambda
v1=1-exp(-q)
v2=beta*(y2-gamma)+1-exp(-p)+4*sqrt(beta)*(sqrt(exp(-1./m))-sqrt(exp(-y2./lambda)))
v=[v1 v2]
%a
plot(m,v)
0 个评论
回答(1 个)
Walter Roberson
2019-4-12
There are several approaches that can be used:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Error Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!