Borrar filtros
Borrar filtros

Summation of different size matrices

1 visualización (últimos 30 días)
David Krouse
David Krouse el 13 de Mayo de 2021
Respondida: Nipun el 15 de Mayo de 2024
I need to summate a small (1x3 matrix) with a large (457x46 matrix). Where eps_x0, exps_y0,eps_xy0 are indivudal numbers, and "curve" values differ per x,y values from the mesh grid. Truth be told I do not even know what the meshgrid does. Coding is very foreign to me, any help would be appreciated. All D values, a and b, and p0 are known, just x and y vary per case.
a = 1.14;
b = 0.57;
[X,Y] = meshgrid(0:0.025:a, 0:0.00125:b);
curve_x = (12.25*p0*((Y.^2-b*Y).^2).*(6*X.^2 - 6*a*X + a^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_y = (12.25*p0*((X.^2-a*X).^2).*(6*Y.^2 - 6*b*Y + b^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_xy = (49*p0*(2*X.^3-3*a*X.^2+a^2*X).*(2*Y.^3-3*b*Y.^2+b^2*Y)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
eps_x0 = eps_0(1)
eps_y0 = eps_0(2)
eps_xy0 = eps_0(3)
eps_x = eps_x0 + curve_x;
eps_y = eps_y0 + curve_y;
eps_xy = eps_xy0 + curve_xy;
  2 comentarios
KSSV
KSSV el 13 de Mayo de 2021
Define all the variables. Many variables are not defined.
David Krouse
David Krouse el 13 de Mayo de 2021
a = 1.14;
b = 0.57;
D11 = 1.15e4
D12 = 3.17e3
D66 = 3.59e3
D22 = 1.12e4
p0 = 0.055e6
eps_x0 = 1.123e-4
eps_y0 = 5.213e-4
eps_xy0 = -0.004
[X,Y] = meshgrid(0:0.025:a, 0:0.00125:b);
curve_x = (12.25*p0*((Y.^2-b*Y).^2).*(6*X.^2 - 6*a*X + a^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_y = (12.25*p0*((X.^2-a*X).^2).*(6*Y.^2 - 6*b*Y + b^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_xy = (49*p0*(2*X.^3-3*a*X.^2+a^2*X).*(2*Y.^3-3*b*Y.^2+b^2*Y)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
eps_x = eps_x0 + curve_x;
eps_y = eps_y0 + curve_y;
eps_xy = eps_xy0 + curve_xy;

Iniciar sesión para comentar.

Respuestas (1)

Nipun
Nipun el 15 de Mayo de 2024
Hi David,
I understand that you are trying to add individual numbers to each element of a large matrix, where the individual numbers are eps_x0, eps_y0, and eps_xy0, and the large matrix is derived from calculations involving a mesh grid. A mesh grid in MATLAB is used to create a grid of points over a specified range, which is useful for evaluating functions over a 2D area. This is particularly handy in simulations and plotting where you need to evaluate expressions at many points.
Given your scenario, you're effectively creating a 2D spatial domain using meshgrid and then calculating curve_x, curve_y, and curve_xy over this domain. To add the individual eps values to each element of the corresponding curve matrices, you can directly add them as you've done. This works because MATLAB supports broadcasting, which means MATLAB automatically expands the smaller array (in this case, the individual numbers) across the larger array during element-wise operations.
Your code snippet correctly performs these operations. Here's a brief explanation and validation of your approach:
% Your given parameters
a = 1.14;
b = 0.57;
D11 = 1.15e4;
D12 = 3.17e3;
D66 = 3.59e3;
D22 = 1.12e4;
p0 = 0.055e6;
eps_x0 = 1.123e-4;
eps_y0 = 5.213e-4;
eps_xy0 = -0.004;
% Generating a mesh grid
[X,Y] = meshgrid(0:0.025:a, 0:0.00125:b);
% Calculating curves
curve_x = (12.25*p0*((Y.^2-b*Y).^2).*(6*X.^2 - 6*a*X + a^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_y = (12.25*p0*((X.^2-a*X).^2).*(6*Y.^2 - 6*b*Y + b^2)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
curve_xy = (49*p0*(2*X.^3-3*a*X.^2+a^2*X).*(2*Y.^3-3*b*Y.^2+b^2*Y)/((7*D11*b^4)+4*a^2*b^2*(D12+2*D66)+(7*D22*a^4)));
% Adding individual numbers to each element of the curve matrices
eps_x = eps_x0 + curve_x;
eps_y = eps_y0 + curve_y;
eps_xy = eps_xy0 + curve_xy;
This code will result in eps_x, eps_y, and eps_xy being matrices of the same dimension as curve_x, curve_y, and curve_xy, with each element of these matrices incremented by eps_x0, eps_y0, and eps_xy0 respectively.
Your approach is correct for adding a scalar value to each element of a matrix in MATLAB, leveraging MATLAB's ability to handle operations between arrays of different sizes through broadcasting.
Hope this helps.
Regards,
Nipun

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by