How to write this equation within Matlab?

  • MATLAB
  • Thread starter hurryon
  • Start date
  • Tags
    Matlab
In summary: You need to use the function abs() to calculate the absolute value:G(i,j)=abs(var0*power((temp(i,j)-M),2))/V);
  • #1
hurryon
9
2
Homework Statement
Hi, guys. I've been reading a paper including some equations. Now, I'd like to write one equation as codes in Matlab. The equation is as following:

E{T} = (ln(v_max / v_min) / v_max - v_min) * E{L}

where E{T} is the expected value of transition time and E{L} is the expected value of transition distance. Also, v_max and v_min mean the maximum speed and the minimum speed, respectively. Note that the speed is a uniform speed distribution within [v_min, v_max].

Thanks in advance.
 
Last edited:
Physics news on Phys.org
  • #2
Are all these quantities scalars?

- Warren
 
  • #3
Yes, they are all scalar values. However, E{T} and E{L} can be vectors.
 
  • #4
Then they aren't all scalars.

Do something like this

Code:
EL = [ 1 2 3 ]
v_min = 1
v_max = 2

ET = (log(v_max / v_min) / (v_max - v_min)) * EL

- Warren
 
  • #5
Thanks for your kind reply. Could you provide one more? The speed values (v_max and v_min) are in a uniform speed distribution within [v_min, v_max].

How do I write that in Matlab? Shall I just use rand() ? (I just want to confirm from others because I'm not an export within Matlab)

Thanks in advance.
 
  • #6
You're aware that Matlab has excellent built-in help, right?

Code:
>> help rand
...
Generate uniform values from the interval [a, b].
           r = a + (b-a).*rand(100,1);

If you just want one random number, use:

Code:
v = v_min + (v_max - v_min) * rand();

- Warren
 
  • #7
Thanks. As you mentioned, Matlab has an excellent help system and I know about that. Sorry, I might annoy you (I just want to get the certain reply from Matlab experts).

Anyway, thanks again!
 
  • #8
hw to design current steering binary weighted dac in matlab

Hi, anybody can u pls suggest homework to design the dac using binary weighted current steering method in matlab.

thanks
 
  • #9
How to write this code in Matlab?

M0=100;
var0=100;

for i=1:478
for j=1:448
if(temp(i,j)>M)
G(i,j)=M0+sqrt(double((var0*power((temp(i,j)-M),2))/V));
else

G(i,j)=M0-sqrt(double((var0*power((temp(i,j)-M),2))/V));

Where temp(i,j) is an matrix. This code is not working. I am getting the values of G as 100. Please help me with the correct code. I am new to matlab.
 

Related to How to write this equation within Matlab?

1. How do I input an equation into Matlab?

To input an equation into Matlab, you can use the symbol "=". For example, to input the equation y = 2x + 5, you would enter "y = 2*x + 5" into the command window.

2. How can I solve an equation using Matlab?

You can use the "solve" function in Matlab to solve equations. For example, if you have the equation x^2 + 5x + 6 = 0, you would enter "solve(x^2 + 5*x + 6 == 0)" into the command window. This will give you the solutions for x.

3. Can I graph an equation in Matlab?

Yes, you can graph an equation in Matlab using the "plot" function. For example, if you want to graph the equation y = x^2, you would enter "plot(x, x^2)" into the command window. This will create a graph of the equation.

4. How can I save an equation in Matlab?

You can save an equation in Matlab by creating a script file. In the script file, you can input your equation and use the "save" function to save it. You can then run the script whenever you need to use the equation again.

5. Can I use variables in my equations in Matlab?

Yes, you can use variables in your equations in Matlab. To define a variable, you can use the symbol "=". For example, to define the variable x as 5, you would enter "x = 5" into the command window. You can then use this variable in your equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
Back
Top