Matlab Error: Undefine Variable

Click For Summary
SUMMARY

The forum discussion addresses a MATLAB error related to an undefined variable 'c' in a 1DOF suspension system model. The user defined 'c' as 2500 in an M-file but encountered an error when trying to evaluate a transfer function. The solution involves declaring 'c' as a global variable to ensure it is accessible across different functions. This approach is supported by MATLAB's documentation on global variables.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with global variables in MATLAB
  • Basic knowledge of dynamic systems modeling
  • Experience with transfer functions in control systems
NEXT STEPS
  • Review MATLAB's documentation on global variables
  • Learn about MATLAB function scopes and variable accessibility
  • Explore dynamic system modeling techniques in MATLAB
  • Investigate the use of transfer functions in control systems analysis
USEFUL FOR

Engineers, students, and researchers working with MATLAB for dynamic systems modeling, particularly those encountering variable scope issues in their simulations.

50Cent
Messages
33
Reaction score
0
Hi,

I am trying to model a simple 1DOF suspension system [mass(ms) 300kg, stiffness(k) 15000N/m, damping coefficient(c) 2500Ns/m. Its subjected to different inputs and then needs to simulate the dynamic response of the system to a road surface that has the characteristics of a flat road, a sine wave surface and then a step.

I completed the model. However, i have now opened the file again and i keep getting the error message:

Error evaluating parameter 'Numerator' in 'HC1/Transfer Fcn': Undefined function or variable 'c'

I have defined "c" as 2500 in the "m" file and the MATLAB working directory is correct as far as i know. I have attached a screen shot of the error. Does any1 know how to solve this problem?
 

Attachments

  • Transfer function Error.JPG
    Transfer function Error.JPG
    44.9 KB · Views: 792
Physics news on Phys.org
I can't tell much from your screen shot. Can you show us your code for 'HC1/Transfer Fcn'? One possible reason for your problem is that you might be using c as if it were a global variable, but it's not. If c is defined in one function and you attempt to use it in another function, I think you will get the error you showed.

If you want to be able to use c in all your functions, make it a global variable. Here is some info about global variables from the online Getting Started documentation for MatLab (http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf)

Global Variables
If you want more than one function to share a single copy of a variable, simply
declare the variable as global in all the functions. Do the same thing at
the command line if you want the base workspace to access the variable.
The global declaration must occur before the variable is actually used in a
function. Although it is not required, using capital letters for the names of
global variables helps distinguish them from other variables. For example,
create an M-file called falling.m:
function h = falling(t)
global GRAVITY
h = 1/2*GRAVITY*t.^2;
Then interactively enter the statements
global GRAVITY
GRAVITY = 32;
y = falling((0:.1:5)');

The two global statements make the value assigned to GRAVITY at the
command prompt available inside the function. You can then modify GRAVITY
interactively and obtain new solutions without editing any files.
 
Hi,

Sorry for the late reply, i have been caught up doing other coursework. I have provided a screen shot of the code for "'HC1/Transfer Fcn"

I will look into changing the global variable. Thanks
 

Attachments

  • transfer function.JPG
    transfer function.JPG
    28.4 KB · Views: 788

Similar threads

  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
16K