Matlab Beginner: Equations with Multiple Variables

Click For Summary
SUMMARY

The discussion focuses on solving equations with multiple variables in MATLAB, specifically using the equation y = x^(6Z+2). A user initially attempted to define the equation in a way that MATLAB could not interpret correctly. The correct approach involves defining the function with the variables in the proper order and using anonymous functions. The final solution provided is to create a function file named functionName that evaluates y at given values of x and z.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with anonymous functions in MATLAB
  • Knowledge of variable assignment in MATLAB
  • Experience with function files in MATLAB
NEXT STEPS
  • Learn how to create and use anonymous functions in MATLAB
  • Explore variable scope and assignment in MATLAB functions
  • Study MATLAB function files and their structure
  • Investigate MATLAB's symbolic math capabilities for complex equations
USEFUL FOR

This discussion is beneficial for beginner MATLAB users, students learning mathematical modeling, and anyone looking to understand function definitions with multiple variables in MATLAB.

rem88
Messages
4
Reaction score
0
Im a begginer at Matlab and have a simple question.

I have a equation with lots of variables that can be easily entered incorrectly.

Therfore i was going to split up the term.

For example if i have y = x^(6Z+2) i was going to put the m file as

y=x^u

u = 6Z + 2

then z = 3 for example.

but i tried something like this and it didnt work, could anyone help me.

function z = f(c)
z = c^h
h=2;
this is what i tried
 
Physics news on Phys.org
You can't do things symbolically like that with plain-jane MATLAB; if you reverse the order of the operations, MATLAB will be happy.

Code:
function z = f(c)
h=2;
z=c^h;
 
y = x^(6Z+2)

Code:
y = @(x,z)(x^(6Z+2))

then to evaluate y at x=3 and z=4, run:

Code:
y(3,4)

or if you want to put it in a m file:
Code:
function y = functionName(x,z)
y = x^(6Z+2);
end

and save it as functionName in your MATLAB directory.

then you would run functionName(3,4) to evaluate y(3,4)
 

Similar threads

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