MATLAB Matlab Error: Undefine Variable

AI Thread Summary
The discussion revolves around a user encountering an error in MATLAB while modeling a simple one-degree-of-freedom suspension system with specific parameters for mass, stiffness, and damping. The error message indicates an undefined variable 'c' in the transfer function. Participants suggest that the issue may stem from the variable 'c' not being recognized across different functions, recommending that it be declared as a global variable to ensure accessibility. The user acknowledges the feedback and plans to implement the suggested changes.
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: 777
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: 767

Similar threads

Replies
1
Views
8K
Replies
3
Views
4K
Replies
1
Views
4K
Replies
4
Views
2K
Replies
3
Views
5K
Replies
12
Views
16K
Back
Top