用labview改寫simulink的程式其中微分部份在LABVIEW要如何寫

![](upload://ynnJIhRp5JuhOFUyEMQicTUX0Ru.jpeg)這是用simulink好的程式

 

這是我打算用labview改寫後的程式![](upload://iXvciOa8jSltuuN5DAwbMJqP660.jpeg)

但是現在遇到一個問題是derivative(微分)的部份

請問labview裡面有derivative的VI嗎

 

 

p2002yu1024b38672.9614930556

在 Block Diagram 呼叫出 Functions 面板 點選最上方的 Search
鍵入關鍵字「derivative」就可以找到你要的功能了。

謝謝大大!!我已經找到derivative了

再請問大大~~當我在simulink模擬時,sign裡面的對話窗有一個這樣的選項![](upload://4ogGR94hVikN2bFJ0MPi5CEhOn6.jpeg)

如果我把框框給勾起來程式便無法正常running

但是改寫成labview後sign.vi![](upload://l761Rs7r6GFVj54mctnpbONW3zA.jpeg)卻沒有這樣的設定

請問這樣的問題在labview下,程式該如何設定或修改

抱歉,沒有用過 simulink
你提到的「Enable zero crossing detection」在 simulink 有什麼作用,
可否說明一下?

看完他的說明之後,其實還是不太懂他在使用上的差別

![](upload://5wDWCk2z60DANApOPiXX73jAW7h.jpeg)

 

不過上面我所寫的程式主要是為了表達這樣一個方程式: u=k1|x1|sgn(s)+k2|x2|sgn(s)+p*sgn(s)

                                                                s=c1*x1+x2

不知道我labview這樣寫有錯嗎??

他的說明如下:Zero-Crossing DetectionWhen simulating a dynamic system, Simulink checks for discontinuities in the system's state variables at each time step, using a technique known as zero-crossing detection. If Simulink detects a discontinuity within the current time step, it determines the precise time at which the discontinuity occurs and takes additional time steps before and after the discontinuity. This section explains why zero-crossing detection is important and how it works. Discontinuities in state variables often coincide with significant events in the evolution of a dynamic system. For example, the instant when a bouncing ball hits the floor coincides with a discontinuity in its position. Because discontinuities often indicate a significant change in a dynamic system, it is important to simulate points of discontinuity precisely. Otherwise, a simulation could lead to false conclusions about the behavior of the system under investigation. Consider, for example, a simulation of a bouncing ball. If the point at which the ball hits the floor occurs between simulation steps, the simulated ball appears to reverse position in midair. This might lead an investigator to false conclusions about the physics of the bouncing ball. To avoid such misleading conclusions, it is important that simulation steps occur at points of discontinuity. A simulator that relies purely on solvers to determine simulation times cannot efficiently meet this requirement. Consider, for example, a fixed-step solver. A fixed-step solver computes the values of state variables at integral multiples of a fixed step size. However, there is no guarantee that a point of discontinuity will occur at an integral multiple of the step size. You could reduce the step size to increase the probability of hitting a discontinuity, but this would greatly increase the execution time. A variable-step solver appears to offer a solution. A variable-step solver adjusts the step size dynamically, increasing the step size when a variable is changing slowly and decreasing the step size when the variable changes rapidly. Around a discontinuity, a variable changes extremely rapidly. Thus, in theory, a variable-step solver should be able to hit a discontinuity precisely. The problem is that to locate a discontinuity accurately, a variable-step solver must again take many small steps, greatly slowing down the simulation. How Zero-Crossing Detection WorksSimulink uses a technique known as zero-crossing detection to address this problem. With this technique, a block can register a set of zero-crossing variables with Simulink, each of which is a function of a state variable that can have a discontinuity. The zero-crossing function passes through zero from a positive or negative value when the corresponding discontinuity occurs. At the end of each simulation step, Simulink asks each block that has registered zero-crossing variables to update the variables. Simulink then checks whether any variable has changed sign since the last step. Such a change indicates that a discontinuity occurred in the current time step. If any zero crossings are detected, Simulink interpolates between the previous and current values of each variable that changed sign to estimate the times of the zero crossings (e.g., discontinuities). Simulink then steps up to and over each zero crossing in turn. In this way, Simulink avoids simulating exactly at the discontinuity, where the value of the state variable might be undefined. Zero-crossing detection enables Simulink to simulate discontinuities accurately without resorting to excessively small step sizes. Many Simulink blocks support zero-crossing detection. The result is fast and accurate simulation of all systems, including systems with discontinuities. Implementation DetailsAn example of a Simulink block that uses zero crossings is the Saturation block. Zero crossings detect these state events in the Saturation block: The input signal reaches the upper limit. The input signal leaves the upper limit. The input signal reaches the lower limit. The input signal leaves the lower limit. Simulink blocks that define their own state events are considered to have intrinsic zero crossings. If you need explicit notification of a zero-crossing event, use the Hit Crossing block. See Blocks with Zero Crossings for a list of blocks that incorporate zero crossings. The detection of a state event depends on the construction of an internal zero-crossing signal. This signal is not accessible by the block diagram. For the Saturation block, the signal that is used to detect zero crossings for the upper limit is zcSignal = UpperLimit - u, where u is the input signal. Zero-crossing signals have a direction attribute, which can have these values: rising - A zero crossing occurs when a signal rises to or through zero, or when a signal leaves zero and becomes positive. falling - A zero crossing occurs when a signal falls to or through zero, or when a signal leaves zero and becomes negative. either - A zero crossing occurs if either a rising or falling condition occurs. For the Saturation block's upper limit, the direction of the zero crossing is either. This enables the entering and leaving saturation events to be detected using the same zero-crossing signal. If the error tolerances are too large, it is possible for Simulink to fail to detect a zero crossing. For example, if a zero crossing occurs within a time step, but the values at the beginning and end of the step do not indicate a sign change, the solver steps over the crossing without detecting it. This figure shows a signal that crosses zero. In the first instance, the integrator steps over the event. In the second, the solver detects the event.Zero-Crossing DetectionWhen simulating a dynamic system, Simulink checks for discontinuities in the system's state variables at each time step, using a technique known as zero-crossing detection. If Simulink detects a discontinuity within the current time step, it determines the precise time at which the discontinuity occurs and takes additional time steps before and after the discontinuity. This section explains why zero-crossing detection is important and how it works. Discontinuities in state variables often coincide with significant events in the evolution of a dynamic system. For example, the instant when a bouncing ball hits the floor coincides with a discontinuity in its position. Because discontinuities often indicate a significant change in a dynamic system, it is important to simulate points of discontinuity precisely. Otherwise, a simulation could lead to false conclusions about the behavior of the system under investigation. Consider, for example, a simulation of a bouncing ball. If the point at which the ball hits the floor occurs between simulation steps, the simulated ball appears to reverse position in midair. This might lead an investigator to false conclusions about the physics of the bouncing ball. To avoid such misleading conclusions, it is important that simulation steps occur at points of discontinuity. A simulator that relies purely on solvers to determine simulation times cannot efficiently meet this requirement. Consider, for example, a fixed-step solver. A fixed-step solver computes the values of state variables at integral multiples of a fixed step size. However, there is no guarantee that a point of discontinuity will occur at an integral multiple of the step size. You could reduce the step size to increase the probability of hitting a discontinuity, but this would greatly increase the execution time. A variable-step solver appears to offer a solution. A variable-step solver adjusts the step size dynamically, increasing the step size when a variable is changing slowly and decreasing the step size when the variable changes rapidly. Around a discontinuity, a variable changes extremely rapidly. Thus, in theory, a variable-step solver should be able to hit a discontinuity precisely. The problem is that to locate a discontinuity accurately, a variable-step solver must again take many small steps, greatly slowing down the simulation. How Zero-Crossing Detection WorksSimulink uses a technique known as zero-crossing detection to address this problem. With this technique, a block can register a set of zero-crossing variables with Simulink, each of which is a function of a state variable that can have a discontinuity. The zero-crossing function passes through zero from a positive or negative value when the corresponding discontinuity occurs. At the end of each simulation step, Simulink asks each block that has registered zero-crossing variables to update the variables. Simulink then checks whether any variable has changed sign since the last step. Such a change indicates that a discontinuity occurred in the current time step. If any zero crossings are detected, Simulink interpolates between the previous and current values of each variable that changed sign to estimate the times of the zero crossings (e.g., discontinuities). Simulink then steps up to and over each zero crossing in turn. In this way, Simulink avoids simulating exactly at the discontinuity, where the value of the state variable might be undefined. Zero-crossing detection enables Simulink to simulate discontinuities accurately without resorting to excessively small step sizes. Many Simulink blocks support zero-crossing detection. The result is fast and accurate simulation of all systems, including systems with discontinuities. Implementation DetailsAn example of a Simulink block that uses zero crossings is the Saturation block. Zero crossings detect these state events in the Saturation block: The input signal reaches the upper limit. The input signal leaves the upper limit. The input signal reaches the lower limit. The input signal leaves the lower limit. Simulink blocks that define their own state events are considered to have intrinsic zero crossings. If you need explicit notification of a zero-crossing event, use the Hit Crossing block. See Blocks with Zero Crossings for a list of blocks that incorporate zero crossings. The detection of a state event depends on the construction of an internal zero-crossing signal. This signal is not accessible by the block diagram. For the Saturation block, the signal that is used to detect zero crossings for the upper limit is zcSignal = UpperLimit - u, where u is the input signal. Zero-crossing signals have a direction attribute, which can have these values: rising - A zero crossing occurs when a signal rises to or through zero, or when a signal leaves zero and becomes positive. falling - A zero crossing occurs when a signal falls to or through zero, or when a signal leaves zero and becomes negative. either - A zero crossing occurs if either a rising or falling condition occurs. For the Saturation block's upper limit, the direction of the zero crossing is either. This enables the entering and leaving saturation events to be detected using the same zero-crossing signal. If the error tolerances are too large, it is possible for Simulink to fail to detect a zero crossing. For example, if a zero crossing occurs within a time step, but the values at the beginning and end of the step do not indicate a sign change, the solver steps over the crossing without detecting it. This figure shows a signal that crosses zero. In the first instance, the integrator steps over the event. In the second, the solver detects the event.Zero-Crossing DetectionWhen simulating a dynamic system, Simulink checks for discontinuities in the system's state variables at each time step, using a technique known as zero-crossing detection. If Simulink detects a discontinuity within the current time step, it determines the precise time at which the discontinuity occurs and takes additional time steps before and after the discontinuity. This section explains why zero-crossing detection is important and how it works. Discontinuities in state variables often coincide with significant events in the evolution of a dynamic system. For example, the instant when a bouncing ball hits the floor coincides with a discontinuity in its position. Because discontinuities often indicate a significant change in a dynamic system, it is important to simulate points of discontinuity precisely. Otherwise, a simulation could lead to false conclusions about the behavior of the system under investigation. Consider, for example, a simulation of a bouncing ball. If the point at which the ball hits the floor occurs between simulation steps, the simulated ball appears to reverse position in midair. This might lead an investigator to false conclusions about the physics of the bouncing ball. To avoid such misleading conclusions, it is important that simulation steps occur at points of discontinuity. A simulator that relies purely on solvers to determine simulation times cannot efficiently meet this requirement. Consider, for example, a fixed-step solver. A fixed-step solver computes the values of state variables at integral multiples of a fixed step size. However, there is no guarantee that a point of discontinuity will occur at an integral multiple of the step size. You could reduce the step size to increase the probability of hitting a discontinuity, but this would greatly increase the execution time. A variable-step solver appears to offer a solution. A variable-step solver adjusts the step size dynamically, increasing the step size when a variable is changing slowly and decreasing the step size when the variable changes rapidly. Around a discontinuity, a variable changes extremely rapidly. Thus, in theory, a variable-step solver should be able to hit a discontinuity precisely. The problem is that to locate a discontinuity accurately, a variable-step solver must again take many small steps, greatly slowing down the simulation. How Zero-Crossing Detection WorksSimulink uses a technique known as zero-crossing detection to address this problem. With this technique, a block can register a set of zero-crossing variables with Simulink, each of which is a function of a state variable that can have a discontinuity. The zero-crossing function passes through zero from a positive or negative value when the corresponding discontinuity occurs. At the end of each simulation step, Simulink asks each block that has registered zero-crossing variables to update the variables. Simulink then checks whether any variable has changed sign since the last step. Such a change indicates that a discontinuity occurred in the current time step. If any zero crossings are detected, Simulink interpolates between the previous and current values of each variable that changed sign to estimate the times of the zero crossings (e.g., discontinuities). Simulink then steps up to and over each zero crossing in turn. In this way, Simulink avoids simulating exactly at the discontinuity, where the value of the state variable might be undefined. Zero-crossing detection enables Simulink to simulate discontinuities accurately without resorting to excessively small step sizes. Many Simulink blocks support zero-crossing detection. The result is fast and accurate simulation of all systems, including systems with discontinuities. Implementation DetailsAn example of a Simulink block that uses zero crossings is the Saturation block. Zero crossings detect these state events in the Saturation block: The input signal reaches the upper limit. The input signal leaves the upper limit. The input signal reaches the lower limit. The input signal leaves the lower limit. Simulink blocks that define their own state events are considered to have intrinsic zero crossings. If you need explicit notification of a zero-crossing event, use the Hit Crossing block. See Blocks with Zero Crossings for a list of blocks that incorporate zero crossings. The detection of a state event depends on the construction of an internal zero-crossing signal. This signal is not accessible by the block diagram. For the Saturation block, the signal that is used to detect zero crossings for the upper limit is zcSignal = UpperLimit - u, where u is the input signal. Zero-crossing signals have a direction attribute, which can have these values: rising - A zero crossing occurs when a signal rises to or through zero, or when a signal leaves zero and becomes positive. falling - A zero crossing occurs when a signal falls to or through zero, or when a signal leaves zero and becomes negative. either - A zero crossing occurs if either a rising or falling condition occurs. For the Saturation block's upper limit, the direction of the zero crossing is either. This enables the entering and leaving saturation events to be detected using the same zero-crossing signal. If the error tolerances are too large, it is possible for Simulink to fail to detect a zero crossing. For example, if a zero crossing occurs within a time step, but the values at the beginning and end of the step do not indicate a sign change, the solver steps over the crossing without detecting it. This figure shows a signal that crosses zero. In the first instance, the integrator steps over the event. In the second, the solver detects the event.Zero-Crossing DetectionWhen simulating a dynamic system, Simulink checks for discontinuities in the system's state variables at each time step, using a technique known as zero-crossing detection. If Simulink detects a discontinuity within the current time step, it determines the precise time at which the discontinuity occurs and takes additional time steps before and after the discontinuity. This section explains why zero-crossing detection is important and how it works. Discontinuities in state variables often coincide with significant events in the evolution of a dynamic system. For example, the instant when a bouncing ball hits the floor coincides with a discontinuity in its position. Because discontinuities often indicate a significant change in a dynamic system, it is important to simulate points of discontinuity precisely. Otherwise, a simulation could lead to false conclusions about the behavior of the system under investigation. Consider, for example, a simulation of a bouncing ball. If the point at which the ball hits the floor occurs between simulation steps, the simulated ball appears to reverse position in midair. This might lead an investigator to false conclusions about the physics of the bouncing ball. To avoid such misleading conclusions, it is important that simulation steps occur at points of discontinuity. A simulator that relies purely on solvers to determine simulation times cannot efficiently meet this requirement. Consider, for example, a fixed-step solver. A fixed-step solver computes the values of state variables at integral multiples of a fixed step size. However, there is no guarantee that a point of discontinuity will occur at an integral multiple of the step size. You could reduce the step size to increase the probability of hitting a discontinuity, but this would greatly increase the execution time. A variable-step solver appears to offer a solution. A variable-step solver adjusts the step size dynamically, increasing the step size when a variable is changing slowly and decreasing the step size when the variable changes rapidly. Around a discontinuity, a variable changes extremely rapidly. Thus, in theory, a variable-step solver should be able to hit a discontinuity precisely. The problem is that to locate a discontinuity accurately, a variable-step solver must again take many small steps, greatly slowing down the simulation. How Zero-Crossing Detection WorksSimulink uses a technique known as zero-crossing detection to address this problem. With this technique, a block can register a set of zero-crossing variables with Simulink, each of which is a function of a state variable that can have a discontinuity. The zero-crossing function passes through zero from a positive or negative value when the corresponding discontinuity occurs. At the end of each simulation step, Simulink asks each block that has registered zero-crossing variables to update the variables. Simulink then checks whether any variable has changed sign since the last step. Such a change indicates that a discontinuity occurred in the current time step. If any zero crossings are detected, Simulink interpolates between the previous and current values of each variable that changed sign to estimate the times of the zero crossings (e.g., discontinuities). Simulink then steps up to and over each zero crossing in turn. In this way, Simulink avoids simulating exactly at the discontinuity, where the value of the state variable might be undefined. Zero-crossing detection enables Simulink to simulate discontinuities accurately without resorting to excessively small step sizes. Many Simulink blocks support zero-crossing detection. The result is fast and accurate simulation of all systems, including systems with discontinuities. Implementation DetailsAn example of a Simulink block that uses zero crossings is the Saturation block. Zero crossings detect these state events in the Saturation block: The input signal reaches the upper limit. The input signal leaves the upper limit. The input signal reaches the lower limit. The input signal leaves the lower limit. Simulink blocks that define their own state events are considered to have intrinsic zero crossings. If you need explicit notification of a zero-crossing event, use the Hit Crossing block. See Blocks with Zero Crossings for a list of blocks that incorporate zero crossings. The detection of a state event depends on the construction of an internal zero-crossing signal. This signal is not accessible by the block diagram. For the Saturation block, the signal that is used to detect zero crossings for the upper limit is zcSignal = UpperLimit - u, where u is the input signal. Zero-crossing signals have a direction attribute, which can have these values: rising - A zero crossing occurs when a signal rises to or through zero, or when a signal leaves zero and becomes positive. falling - A zero crossing occurs when a signal falls to or through zero, or when a signal leaves zero and becomes negative. either - A zero crossing occurs if either a rising or falling condition occurs. For the Saturation block's upper limit, the direction of the zero crossing is either. This enables the entering and leaving saturation events to be detected using the same zero-crossing signal. If the error tolerances are too large, it is possible for Simulink to fail to detect a zero crossing. For example, if a zero crossing occurs within a time step, but the values at the beginning and end of the step do not indicate a sign change, the solver steps over the crossing without detecting it. This figure shows a signal that crosses zero. In the first instance, the integrator steps over the event. In the second, the solver detects the event.Zero-Crossing DetectionWhen simulating a dynamic system, Simulink checks for discontinuities in the system's state variables at each time step, using a technique known as zero-crossing detection. If Simulink detects a discontinuity within the current time step, it determines the precise time at which the discontinuity occurs and takes additional time steps before and after the discontinuity. This section explains why zero-crossing detection is important and how it works. Discontinuities in state variables often coincide with significant events in the evolution of a dynamic system. For example, the instant when a bouncing ball hits the floor coincides with a discontinuity in its position. Because discontinuities often indicate a significant change in a dynamic system, it is important to simulate points of discontinuity precisely. Otherwise, a simulation could lead to false conclusions about the behavior of the system under investigation. Consider, for example, a simulation of a bouncing ball. If the point at which the ball hits the floor occurs between simulation steps, the simulated ball appears to reverse position in midair. This might lead an investigator to false conclusions about the physics of the bouncing ball. To avoid such misleading conclusions, it is important that simulation steps occur at points of discontinuity. A simulator that relies purely on solvers to determine simulation times cannot efficiently meet this requirement. Consider, for example, a fixed-step solver. A fixed-step solver computes the values of state variables at integral multiples of a fixed step size. However, there is no guarantee that a point of discontinuity will occur at an integral multiple of the step size. You could reduce the step size to increase the probability of hitting a discontinuity, but this would greatly increase the execution time. A variable-step solver appears to offer a solution. A variable-step solver adjusts the step size dynamically, increasing the step size when a variable is changing slowly and decreasing the step size when the variable changes rapidly. Around a discontinuity, a variable changes extremely rapidly. Thus, in theory, a variable-step solver should be able to hit a discontinuity precisely. The problem is that to locate a discontinuity accurately, a variable-step solver must again take many small steps, greatly slowing down the simulation. How Zero-Crossing Detection WorksSimulink uses a technique known as zero-crossing detection to address this problem. With this technique, a block can register a set of zero-crossing variables with Simulink, each of which is a function of a state variable that can have a discontinuity. The zero-crossing function passes through zero from a positive or negative value when the corresponding discontinuity occurs. At the end of each simulation step, Simulink asks each block that has registered zero-crossing variables to update the variables. Simulink then checks whether any variable has changed sign since the last step. Such a change indicates that a discontinuity occurred in the current time step. If any zero crossings are detected, Simulink interpolates between the previous and current values of each variable that changed sign to estimate the times of the zero crossings (e.g., discontinuities). Simulink then steps up to and over each zero crossing in turn. In this way, Simulink avoids simulating exactly at the discontinuity, where the value of the state variable might be undefined. Zero-crossing detection enables Simulink to simulate discontinuities accurately without resorting to excessively small step sizes. Many Simulink blocks support zero-crossing detection. The result is fast and accurate simulation of all systems, including systems with discontinuities. Implementation DetailsAn example of a Simulink block that uses zero crossings is the Saturation block. Zero crossings detect these state events in the Saturation block: The input signal reaches the upper limit. The input signal leaves the upper limit. The input signal reaches the lower limit. The input signal leaves the lower limit. Simulink blocks that define their own state events are considered to have intrinsic zero crossings. If you need explicit notification of a zero-crossing event, use the Hit Crossing block. See Blocks with Zero Crossings for a list of blocks that incorporate zero crossings. The detection of a state event depends on the construction of an internal zero-crossing signal. This signal is not accessible by the block diagram. For the Saturation block, the signal that is used to detect zero crossings for the upper limit is zcSignal = UpperLimit - u, where u is the input signal. Zero-crossing signals have a direction attribute, which can have these values: rising - A zero crossing occurs when a signal rises to or through zero, or when a signal leaves zero and becomes positive. falling - A zero crossing occurs when a signal falls to or through zero, or when a signal leaves zero and becomes negative. either - A zero crossing occurs if either a rising or falling condition occurs. For the Saturation block's upper limit, the direction of the zero crossing is either. This enables the entering and leaving saturation events to be detected using the same zero-crossing signal. If the error tolerances are too large, it is possible for Simulink to fail to detect a zero crossing. For example, if a zero crossing occurs within a time step, but the values at the beginning and end of the step do not indicate a sign change, the solver steps over the crossing without detecting it. This figure shows a signal that crosses zero. In the first instance, the integrator steps over the event. In the second, the solver detects the event.

![](upload://absRx3Ab2HsIH7fEkAvP9pNwhlC.jpeg)

p2002yu1024b38686.5428819444

先跟你說抱歉,沒辦法看完整個說明 (好多呀  )

如果你只是單純要實現 方程式

  • u=k1|x1|sgn(s)+k2|x2|sgn(s)+p*sgn(s)

    s=c1*x1+x2

那麼你現在的程式應該就適用了。

我稍稍看了一下說明及你所附上的圖解,應該是底下的情況:
(這邊還請真正懂的人來說明下,)

那個「Enable zero crossing detection」,應該是在 多於一次程式執行
的情況下會產生作用 。

當輸入該 元件 的值與上一次的 輸入 是相差一個負號的話,才會被偵測到。

你在 simulink 可以針對這個特性再試試看,有什麼結果。