Matlab Beginner: Equations with Multiple Variables

Name(3,z) to evaluate y(3,z).In summary, the conversation discusses the process of splitting up a term in an equation with multiple variables in order to avoid inputting incorrect values. The code for this process involves defining a function and using it to evaluate the equation at specific values for the variables.
  • #1
rem88
5
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
  • #2
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;
 
  • #3
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)
 

1. How do I solve equations with multiple variables in Matlab?

To solve equations with multiple variables in Matlab, you can use the "solve" function. This function takes in the equations as input and outputs the solutions for the variables. For example, if you have the equations x + y = 5 and 2x + 3y = 12, you can use the command "solve('x + y = 5', '2x + 3y = 12')" to get the solution x = 3, y = 2.

2. Can I solve systems of equations with more than two variables in Matlab?

Yes, you can solve systems of equations with any number of variables in Matlab using the "solve" function. However, it is important to note that as the number of variables increases, the complexity of the equations and the time taken to compute the solutions also increases.

3. How do I plot equations with multiple variables in Matlab?

To plot equations with multiple variables in Matlab, you can use the "ezplot" function. This function takes in the equation as input and automatically generates a plot for the specified range of values for the variables. For example, if you have the equation y = x^2 + 2x, you can use the command "ezplot('x^2 + 2x')" to plot the graph.

4. Can I use matrices to solve equations with multiple variables in Matlab?

Yes, you can use matrices to solve equations with multiple variables in Matlab. The "solve" function can take in matrices as input instead of individual equations. This can be useful when dealing with large systems of equations with many variables.

5. Is it possible to solve equations with multiple variables using symbolic variables in Matlab?

Yes, you can use symbolic variables in Matlab to solve equations with multiple variables. This allows you to work with algebraic expressions instead of numerical values, making it easier to manipulate and solve complex equations. The "solve" function also supports symbolic variables as input.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
821
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
994
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top