Plotting Variables (b,u) in Function "Step"

Click For Summary
SUMMARY

The discussion focuses on plotting variables (b, u) within the context of the MATLAB function "step" using the ODE solver ode45. The user seeks to access the variables b and u defined in the nested function "step" from the main function. The solution involves utilizing the MATLAB documentation for ode45 to understand how to extract and plot these variables effectively. The key takeaway is that the user can modify the plotting code to include the necessary variables after solving the ODE.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of ordinary differential equations (ODEs)
  • Knowledge of MATLAB's ode45 function
  • Basic plotting techniques in MATLAB
NEXT STEPS
  • Review MATLAB's documentation on ode45 for advanced usage
  • Learn how to return multiple outputs from functions in MATLAB
  • Explore MATLAB plotting functions to visualize multiple variables
  • Study the concept of state variables in ODEs for better understanding
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those working with numerical methods for solving ODEs, as well as engineers and scientists looking to visualize dynamic systems.

madjid222
Messages
4
Reaction score
0
Hi Friends
I want to plot variables (b,u) that are in function "step" .
function main
[t,v]=ode45('step',[0 20],0,[]);
plot(t,v)

function dv=step(t,v)
c1=1;
if t<10
u=1;
else
u=-1;
end
dv=c1*u-2*v;
b=dv/2;


but these variables are unknown in function "main".
thanks.
 
Physics news on Phys.org
please help me
 
This should solve your problem:

Code:
doc ode45
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K