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

29 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Matt J
Matt J el 3 de Oct. de 2021
Editada: Matt J el 3 de Oct. de 2021
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

Más respuestas (1)

the cyclist
the cyclist el 3 de Oct. de 2021
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 comentarios
the cyclist
the cyclist el 4 de Oct. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Least Squares en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by