简体   繁体   中英

Plotting an equation with two input variables using meshgrid() in MATLAB - matrix incompatibility

I am trying to plot a 3D graph of an equation that has two input variables: time, t and spring constant, K in order to investigate the effect of K on the output. I have looked in to how to plot a function with two input variables using meshgrid() and converting the two inputs into compatible matrices.

For multiplying one of those inputs, say 't'. The multiplication sign needs to be preceded by '.' eg y = t.*C (where C is some constant). For two inputs it is the same; eg y = t.*C + K.^2 .

However I cannot find how to do that for division, if the variable is in the numerator I assume you can simply write the expression as say: t*1/C . However how do you write it when the variable is in the denominator as in 'C/t' . I have tried placing '.' after 't' in the denominator however I get an error:

Error using /
Matrix dimensions must agree.

Also do I need to put the '.' after the variable in an addition?

Apologies if all this seems vague. I can put in the actual equation however it extremely long and it works when only t is a variable and K is a constant so the equation itself is sound.

The operations that have to be preceded with a . to apply element-wise are:

  • Multiplication: .*
  • Division: ./
  • Power: .^

Thus, if A , B , and C are arrays, you write

y = (A.*B./C).^2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM