difficult in programming two velocity law into one profile

1 vue (au cours des 30 derniers jours)
Souvick roy
Souvick roy le 11 Avr 2019
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)

Réponses (1)

Walter Roberson
Walter Roberson le 12 Avr 2019
There are several approaches that can be used:
  1. 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)
  2. 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')
  3. 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
  4. 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
  5. 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.)

Catégories

En savoir plus sur Error Functions dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by