0

mfunction.m

function[P] = mfunction(v,M,R,T)
P=4*pi*(M/(2*pi*R*T)).^(3/2)*v.^2*exp((-M*(v.^2))/(2*R*T));
end

I want to make a graph. x would be v and the range is 1: 1200,

M = 0.032,R = 8.31, T= 300 

and I want to plot y=mfunction(x)

and errors pop up. How can I draw a graph?

2
  • What's the error you are getting? Commented Feb 28, 2014 at 6:28
  • >>x=1:1200; >>y=mfunction(x,4,8,100); ??? Error using ==> mtimes Inner matrix dimensions must agree. Error in ==> mfunction at 2 P=4*pi*(M/(2*piRT)).^(3/2)*v.^2*exp((-M*(v.^2))/(2*R*T)); Commented Feb 28, 2014 at 6:29

1 Answer 1

1

The problem lies at the middle multiplication

P=4*pi*(M/(2*pi*R*T)).^(3/2)*v.^2  *   exp((-M*(v.^2))/(2*R*T));
                                   ^

What you are doing is similar to doing

[1,2] * [1,2]

, which gives you the error "mtimes Inner matrix dimensions must agree", because it is multiplying a mx1 matrix to an mx1 matrix.

Depending on want you need, you can do one of the following:

>> [1,2] * [1,2]'  %inner product

ans =

     5

>> [1,2]' * [1,2]

ans =

     1     2
     2     4

>> [1,2] .* [1,2]  %element-wise product

ans =

     1     4
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.