How can I divide by the function variable in a Simulink equation?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to solve this fairly simple second order differential equation using Simulink:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700076/image.png)
Which I rewrote as:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700081/image.png)
The problem is that
is another function of r, and because of that I cannot divide
by a constant as is normally done when solving differential equations in Simulink.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700086/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700091/image.png)
![How can I divide by r in my Simulink equation solver](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700096/How%20can%20I%20divide%20by%20r%20in%20my%20Simulink%20equation%20solver.png)
How can I divide by r in my Simulink model?
2 Commenti
Pat Gipper
il 21 Mag 2024
The output of the second integrator should be the solution to your second order equation. Why not feed it into the divide? One word of warning is that Simulink will be solving with a starting value of 0, so you will be dividing by 0 right from the start. To avoid this error try feeding a non-zero initial condition into the second integrator.
Risposta accettata
Sam Chak
il 21 Mag 2024
Hi @Louis
In the 2nd-order ODE, the independent variable 'r' can represent the radius of the system or another relevant parameter. However, in Simulink, the simulation runs based on the flow of time 't', which is the fundamental independent variable in many dynamic systems. To account for this, you can configure 1/r as if it were 1/t.
This approach, however, may introduce a division-by-zero issue if t starts from 0. To address the potential singularity, you can utilize the Ramp block and configure it accordingly. By setting the Slope to 1, the independent variable r will propagate linearly with respect to Simulink time. Additionally, selecting a positive Initial Output (which corresponds to r) will help avoid the singularity. In the Model Configuration Parameters menu, you can set the Start time to be equal to the Initial Output value.
To verify the results obtained in Simulink, a simple MATLAB code. Comparing the outputs from both the Simulink model and the MATLAB code will help ensure the consistency of your implementation.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700631/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700636/image.png)
k = 1;
mu = 1;
ode = @(r, v) [v(2);
k/mu - (1/r)*v(2)];
rspan = [1, 6]; % r starts from 1 and ends at 6
v0 = [1; 0]; % initial values: v(1) = 1, v'(1) = 0
[r, v] = ode45(ode, rspan, v0);
plot(r, v(:,1)), grid on, xlabel r, ylabel v, ylim([0 10])
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!