How to create a matrix using two arrays (x & y) and a formula that uses x & y

29 次查看(过去 30 天)
So if
x = [4.0:-.05:3.7]
&
y = [9;15;21;27;33;39;45]
&
z = 1.3473*152/(152+y)+(5-x)*y/(152+y)
How do I create a matrix that calculates output z at the different possible combinations of x & y?

采纳的回答

Matt J
Matt J 2021-10-3
编辑:Matt J 2021-10-3
Use implict expansion.
x = [4.0:-.05:3.7] ;
y = [9;15;21;27;33;39;45];
z = 1.3473*152./(152+y)+(5-x).*y./(152+y)
z = 7×7
1.3279 1.3307 1.3335 1.3363 1.3391 1.3419 1.3447 1.3161 1.3206 1.3251 1.3296 1.3341 1.3386 1.3431 1.3051 1.3112 1.3173 1.3234 1.3294 1.3355 1.3416 1.2949 1.3025 1.3100 1.3175 1.3251 1.3326 1.3402 1.2853 1.2943 1.3032 1.3121 1.3210 1.3299 1.3389 1.2764 1.2866 1.2968 1.3070 1.3172 1.3274 1.3376 1.2680 1.2794 1.2908 1.3022 1.3137 1.3251 1.3365

更多回答(1 个)

the cyclist
the cyclist 2021-10-3
Use the meshgrid function to create 2-dimensional grids from the x and y vectors. The first example in the documentation is very similar to what you want to do.
  3 个评论
the cyclist
the cyclist 2021-10-4
x = [4.0:-.05:3.7] ;
y = [9;15;21;27;33;39;45];
[xx,yy] = meshgrid(x,y);
z = 1.3473*152./(152+yy)+(5-xx).*yy./(152+yy)
z = 7×7
1.3279 1.3307 1.3335 1.3363 1.3391 1.3419 1.3447 1.3161 1.3206 1.3251 1.3296 1.3341 1.3386 1.3431 1.3051 1.3112 1.3173 1.3234 1.3294 1.3355 1.3416 1.2949 1.3025 1.3100 1.3175 1.3251 1.3326 1.3402 1.2853 1.2943 1.3032 1.3121 1.3210 1.3299 1.3389 1.2764 1.2866 1.2968 1.3070 1.3172 1.3274 1.3376 1.2680 1.2794 1.2908 1.3022 1.3137 1.3251 1.3365

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by