Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using the fsolve command 1

Status
Not open for further replies.

plvachon

Mechanical
Jun 16, 2005
38
0
0
CA
Hello all,

My question relates to Matlab syntax and the way Matlab communicates between M-files and function files. I am trying to solve a system of 2 non-linear equations (with 2 unknowns) using the fsolve command. I wrote a function (function solu = myequations(guess)) that contains my 2 equations, and then in the "main" M-file I can call the fsolve function (in combination with my initial guess) and get an answer.
My problem is that the 2 equations depend on several constants I define at the beginning of the main M-file, and these constants are not available in the function file... These constants are subjected to change from one material to another, so I would like to keep all the variables and constants in the main file instead of defining them in the function file. Is there a way to define my equations in the function file so that they relate to the constants defined in the main M-file? If is not clear enough, feel free to tell!

thanks in advance!
 
Replies continue below

Recommended for you

As I see it you have two choices.

1 - Create global variables and store you constants there.
The first line in your main file would be
global const1 const2 const3

The first line after function solu = myequations(guess)would again be
global const1 const2 const3

2 - Pass you constants as part of the function call to your function.
solu = myequations(guess,const1, const2,const3)



=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Status
Not open for further replies.
Back
Top