How to apply an equation to each element in the array?

I have an equation:
Which I need to apply to every element in a 10x10 matrix of u.
u - a node in numerical model of rock layer
j,n - indexes of movement
The matrix is supposed to have identical starting values of 80.

 Risposta accettata

conv( u , [0 1 0]+alpha*[1 -2 1] )

5 Commenti

Thanks for help! I tried to implement that conv function into my code, but it returns an error 'Invalid data type' and 'c = conv2(a(:),b(:),shape);'
I tried to rewrite it, simply as conv( u, j ); with j=[0 1 0]+alpha*[1 -2 1] but it still demands two vectors A B.
I have my code pretty much finished. All I need now, is an idea how to run the equation through the nodes so it will calculate the pressure.
Your code is an image, so I am unable to copy/paste it. However, I suspect that if you remove the line,
syms alpha u
it will work as expected.
nope. I've already tried it and it doesn''t work, with syms alpha u removed, and lines
j=[0 1 0]+alpha*[1 -2 1]
soilSub = conv( u, j )
You still get matlab error about two vectors A B
Here's the code in copy/paste form if you want to test it yourself:
-----------------------------------------------------------------------------------------------
k = 10^-7 % filtration of soil
M = 19000
q = 80 % external force Q acting on soil
DeltaZ = 0.1 % depth of soil subsidization
GammaW = 10 % water weight [Kn/m^3]
Cv = k*M/GammaW % consolidation factor
DeltaT = DeltaZ^2/(2*Cv) % max iteration step
alpha = Cv*DeltaT/DeltaZ^2
% NUMERICAL PARAMETERS
u = q*ones(10:10) % matrix of u nodes
%symbolic variables
% SOLUTION
% discrete form of the governing equation:
soilSub = conv( u, [0 1 0]+alpha*[1 -2 1] );
-----------------------------------------------------
You know I'm pretty new to MATLAB using it for 6 weeks or so, I probably do not have enough knowledge for advanced models. I do not expect folks here will do my homework for me :) but I'm eager to discuss methods in which you can: 1) build a model of rock layer 2) implement finite difference equation to that model so it goes through it and computes external pressure.
Use conv2 instead
soilSub = conv2( u, [0 1 0]+alpha*[1 -2 1] )
IT WORKS! Thank you very much for your valuable advice!

Accedi per commentare.

Più risposte (1)

Try conv2():
k = 10^-7 % filtration of soil
M = 19000
q = 80 % external force Q acting on soil
DeltaZ = 0.1 % depth of soil subsidization
GammaW = 10 % water weight [Kn/m^3]
Cv = k*M/GammaW % consolidation factor
DeltaT = DeltaZ^2/(2*Cv) % max iteration step
alpha = Cv*DeltaT/DeltaZ^2
% NUMERICAL PARAMETERS
u = q*ones(10:10) % matrix of u nodes
% SOLUTION
kernel = [0, 1, 0] + alpha * [1, -2, 1]
% Discrete form of the governing equation:
soilSub = conv2(u, kernel) % Use conv2(), not conv()

4 Commenti

Glad using conv2() instead of conv() solved your issue.
KarolN
KarolN il 28 Nov 2021
Modificato: KarolN il 28 Nov 2021
IT WORKS! Thanks very much for valuable advice!
NOTE: I decided to accept answer of Matt J since he posted this idea first, and it would be unfair to omit him, howewer I consider both his and yours answers to be equally worthy.
No problem. I'm sure using conv() instead of conv2() was just an oversight by Matt. I know he knows better - he's a bright guy. You can vote for multiple answers though you can only Accept one. You can even vote for one you Accepted to award double the reputation points to that one.
And so additionally I learned about that vote feat :) Voted for both of you naturally. Thanks guys

Accedi per commentare.

Categorie

Scopri di più su Agriculture in Centro assistenza e File Exchange

Prodotti

Release

R2020b

Richiesto:

il 27 Nov 2021

Commentato:

il 28 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by