meshgrid
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
dimensions of X and Y are as given below
X = 1X89000 Y = 1X 89000
[uxmesh, uymesh] = meshgrid(X,Y);
would you please tell me what is wrong in the above statements? Whenever I execute the above statements, MATLAB keeps crashing..
1 Commento
Jasmina
il 18 Giu 2024
1)
Q = 5e-9; %ładunek [C]
a = 0.4; %bok kwadratu[m]
k = 9e9; % stała Coulomba
EPS0 = 8.85e-12; %[F/m]
positions = [
-a/2, -a/2; %Q1
-a/2, a/2; %Q2
a/2, -a/2; %Q3
a/2, a/2; %Q4
];
charges = [-Q, Q, Q, -Q]; %wartości ładunków
x = linspace(-0.3, 0.3, 100);
y = linspace(-0.3, 0.3, 100);
[X, Y] = meshgrid(x, y); %siatka punktów w przestrzeni
V = zeros(size(X));
Ex = zeros(size(X));
Ey = zeros(size(Y));
%obliczanie potencjału i natężenia pola elektrycnzego
for k = 1:lenght(charges)
r = sqrt((X - positions(k, 1)).^2 + (Y - positions(k, 2)).^2);
V = V + charges(k) ./ (4*pi*EPS0*r);
Ex = Ex + charges(k) * (X - positions(k, 1)) ./ (4*pi*EPS0*r.^3);
Ey = Ey + charges(k) * (Y - positions(k, 2)) ./ (4*pi*EPS0*r.^3);
end
figure;
contourf(X, Y, V, 50, 'LineColor', 'none');
colorbar;
title('mapa potencjału elektrycznego');
xlabel('x[m]');
ylabel('y[m]');
hold on;
quiver(X, Y, Ex, Ey);
hold off;
2)
Q = 5e-9; %ładunek [C]
a = 0.4; %bok kwadratu[m]
k = 9e9; % stała Coulomba
EPS0 = 8.85e-12; %[F/m]
%pozycje ładunków
positions = [
-a/2, -a/2; %Q1
-a/2, a/2; %Q2
a/2, -a/2; %Q3
a/2, a/2; %Q4
];
charges = [-Q, Q, Q, -Q]; %wartości ładunków
x = linspace(-0.3, 0.3, 100);
y = linspace(-0.3, 0.3, 100);
[X, Y] = meshgrid(x, y); %siatka punktów w przestrzeni
V = zeros(size(X));
Ex = zeros(size(X));
Ey = zeros(size(Y));
%obliczanie potencjału i natężenia pola elektrycnzego
for k = 1
(charges)
r = sqrt((X - positions(k, 1)).^2 + (Y - positions(k, 2)).^2);
V = V + charges(k) ./ (4piEPS0*r);
s
Ex = Ex + charges(k) * (X - positions(k, 1)) ./ (4*pi*EPS0*r.^3);
Ey = Ey + charges(k) * (Y - positions(k, 2)) ./ (4*pi*EPS0*r.^3);
end
figure;
contourf(X, Y, V, 50, 'LineColor', 'none');
colorbar;
title('mapa potencjału elektrycznego');
xlabel('x[m]');
ylabel('y[m]');
hold on;
quiver(X, Y, Ex, Ey);
hold off;
3)
Q1 = 10e-9; %ładunek 1 [C]
Q2 = -1e-9; %ładunek 2 [C]
a = 0.1; %bok kwadratu [m]
k = 8.99e9; %stała Coulomba
%pozycje ładunków
M1 = [-a/2, a/2];
M2 = [a/2, -a/2];
N = 100;
t = linspace(0, 1, N);
x_path = M1(1) + t * (M2(1) - M1(1));
y_path = M1(2) + t * (M2(2) - M1(2));
W = 0;
for i = 1:N-1
r = sqrt((x_path(i) - 0).^2 + (y_path(i) - 0).^2);
F = k * Q1 * Q2 / r^2; %siła Coulomba
dx = x_path(i+1) - x_path(i);
dy = y_path(i+1) - y_path(i);
dl = sqrt(dx^2 + dy^2);
W = W + F * dl;
end
disp(['praca wykonana przez sile elektryczną: ', num2str(W), 'J']);
3)
Q = 8e-9; %ładunek [C]
a = 0.4; %długość boku trójkąta [m]
k = 8.99e9; %stała Coulomba
EPS0 = 8.85e-12; %przenikalność elek. próżni
h = (sqrt(3)/2)*a; %wysokość trójkąta
positions = [
0, -h/3;
a/2, h*2/3; %pozycje ładunków
-a/2, h*2/3;
];
charges = [Q, -Q, Q];
x = linspace(-0.3, 0.3, 100); %siatka punktów w przestrzeni
y = linspace(-0.3, 0.3, 100);
[X, Y] = meshgrid(x, y);
V = zeros(size(X));
Ex = zeros(size(X));
Ey = zeros(size(Y));
%obliczanie potencjału i natężenia pola elektrycnzgeo
for k = 1:length(charges)
r = sqrt((X - positions(k, 1)).^2 + (Y - positions(k, 2)).^2);
V = V + charges(k) ./ (4*pi*EPS0*r);
Ex = Ex + charges(k) * (X - positions(k, 1)) ./ (4*pi*EPS0*r.^3);
Ey = Ey + charges(k) * (X - positions(k, 2)) ./ (4*pi*EPS0*r.^3);
end
figure;
contourf(X, Y, V, 50, 'LineColor', 'none');
colorbar;
title('mapa potencjału elektrycznego');
xlabel('x[m[');
ylabel('y[m]');
hold on;
quiver(X, Y, Ex, Ey);
hold off;
4)
Q = 8e-9; %ładunek [C]
a = 0.4; %długość boku trójkąta [m]
k = 8.99e9; %stała Coulomba
EPS0 = 8.85e-12; %przenikalność elek. próżni
h = (sqrt(3)/2)*a; %wysokość trójkąta
positions = [
0, -h/3;
a/2, h*2/3; %pozycje ładunków
-a/2, h*2/3;
];
charges = [Q, -Q, Q];
x = linspace(-0.3, 0.3, 100); %siatka punktów w przestrzeni
y = linspace(-0.3, 0.3, 100);
[X, Y] = meshgrid(x, y);
V = zeros(size(X));
Ex = zeros(size(X));
Ey = zeros(size(Y));
%obliczanie potencjału i natężenia pola elektrycnzgeo
for k = 1:length(charges)
r = sqrt((X - positions(k, 1)).^2 + (Y - positions(k, 2)).^2);
V = V + charges(k) ./ (4*pi*EPS0*r);
Ex = Ex + charges(k) * (X - positions(k, 1)) ./ (4*pi*EPS0*r.^3);
Ey = Ey + charges(k) * (X - positions(k, 2)) ./ (4*pi*EPS0*r.^3);
end
figure;
contourf(X, Y, V, 50, 'LineColor', 'none');
colorbar;
title('mapa potencjału elektrycznego');
xlabel('x[m[');
ylabel('y[m]');
hold on;
quiver(X, Y, Ex, Ey);
hold off;
Risposte (2)
Matt Fig
il 8 Giu 2011
Are you running out of memory? Why not tell us what prompted you to ask the question???
There is nothing syntactically wrong with the statement. However, you better have
8*2*89000^2 bytes (read: LOTS!!) of free memory, assuming X and Y are doubles...
5 Commenti
Matt Fig
il 8 Giu 2011
In that case I would think it would be acceptable to use a FOR loop and loop over the calculated velocities one at a time to find where in the list of true velocities the closest number lies, like:
[err(ii), idx(ii)] = min(abs(cv(ii)-tv));
Walter Roberson
il 8 Giu 2011
Current versions of interp2() do not require meshgrid(). The documentation says (at least as of 2008b):
XI and YI can be matrices, in which case interp2 returns the values of Z corresponding to the points (XI(i,j),YI(i,j)). Alternatively, you can pass in the row and column vectors xi and yi, respectively. In this case, interp2 interprets these vectors as if you issued the command meshgrid(xi,yi).
Walter Roberson
il 8 Giu 2011
Are X and Y vectors? If so, then the above should work, but only if you have enough memory: 89000 x 89000 double precision numbers requires between 59 and 60 gigabytes.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!