본문 바로가기
유용한 지식/Matlab

Tips for Matlab Equation

by 그래도_明 2020. 9. 24.

Tips for Matlab Equation

When organizing or calculating complex expressions, I have now become a body that cannot be solved without the Matlab.

I will introduce some useful functions with examples when using Matlab, an all-around calculator for engineering students.

 

1. Generate Character Variables | syms

Use it when you want to express variables in an equation. Let's not make a mistake of putting = after syms.

syms x1 x2
y = x1 + x2 + 1

<Syms Example Results>

2. Finding Root of Equation, Organizing Formula | solve

It's good when you're looking for the solution of an equation. It can be entered in the form of solve(equation, variable).

syms x
f = x^2 - 4 == 0;
solve(f,x)

<Solve Function Example Results (1)>

It can also be used to organize specific variables. The following is the result of equation f for x1.

 

syms x1 x2
f = x1^2 +x2 - 4 == 0;
x1 = solve(f,x1)

<Solve Function Example Results (2)>

3. Substitute Value for Character variable, Replace Variable | subs

The equation can be calculated by substituting value for character variable created using syms.

syms x
f = x^2 - 4;
f_4 = subs(f,x,4)

<Subs Function Example Results (1)>

Of course, it is also possible to replace it with other character variable.

syms x t
f = x^2 - 4;
f_t = subs(f,x,2*t)

<Subs Function Example Results (2)>

4. Organizing the order of variables | collect

It is useful when you want to organize into specific variables in a compelx equation.

syms x y
coeffs_x = collect(x^2*y + y*x - x^2 - 2*x, x)
coeffs_y = collect(x^2*y + y*x - x^2 - 2*x, y)

<Collect Function Example Results>

5. To Express at a Glance Easily | pretty

The name of the function is pretty. Draw complex formulas easily.

 

syms x
f = sqrt(x^2 + 1)/(2*x + 4);
pretty(f)

<Pretty Function Example Results>

 

 

Even if you know this much, I think it's good for you to write reports or papers at school. I hope you use it usefully when you are too lazy to write by hand or when you don't believe in your calculations.

반응형

댓글