Problem with mesh grid and intersection of two surfaces
古いコメントを表示
Hello everyone,
I’m trying to plot the intersection points between two second-order polynomial equations. These equations depend on two variables, a and b, which I define as vectors.
To evaluate the solutions, I use meshgrid to create all combinations of a and b. However, this leads to an issue: for a single root (solution), the same value of a appears repeatedly in the result. This causes my plot to show vertical lines instead of individual points, since multiple identical a values are associated with different b values (or vice versa).
Ideally, for each unique pair (a, b), I want to obtain a unique solution. But using meshgrid evaluates all possible combinations, including repeated values for a or b.
I’d appreciate any advice on how to better approach this problem, particularly in terms of how to structure the evaluation and plotting to avoid this repetition and get cleaner, more accurate plots.
Thanks in advance!
5 件のコメント
We will need you to run your code for us (here in the online environment) to illustrate the problem. Off the top there are a few things I don't understand.
(1) If a and b are the dependent variables, it's hard to see why repititions in either a or b would cause vertical lines. They should be on the xy axes.
(2) Ideally, for each unique pair (a, b), I want to obtain a unique solution. Why would that be expected? If these are 2nd order equations, there could be as many as two real solutions. Or none.
Zac Lee
2025 年 8 月 1 日
My ptoblem, is that, i'm having multiple times the same value ffor a and b for the same root.
Are you trying to develop a mapping from (a,b) to the roots, or the other way around? If you are mapping from (a,b) to the roots then it shouldn't matter if there are multiple (a,b) that map to the same root.
If you are mapping from the roots back to (a,b) then you first have to map the roots to a set of polynomial coefficients and then map the coefficients to (a,b). Bear in mind though that polynomial coefficients are unique only up to a scale factor - so you need to decide on some way to remove that ambiguity, before you can map the coefficients to a unique (a,b).
Zac Lee
2025 年 8 月 2 日
採用された回答
その他の回答 (1 件)
Perhaps as follows:
tol = 1e-8;
pas = 0.001;
[N11, N31] = meshgrid(0:pas:0.01); N11=N11(:); N31=N31(:);
%% Polynôme 1
A1 = N11.^2;
B1 = 2 .* N11 .* N31.^2;
C1 = (5 .* N11.^2 + 3 .* N31);
%% Polynôme 2
A2 = N31.^2;
B2 = N31 + N11 .* N31.^3;
C2 = N31 .* N11.^2 + N31 .* N11.^3 + 1;
%% Intersection
A = A1 - A2;
B = (B1 - B2)./A; %normalize leading coefficient
C = (C1 - C2)./A; %normalize leading coefficient
D=B.^2-4*C; %Discriminant
R1=(-B-sqrt(D))/2; %First root
R2=(-B+sqrt(D))/2; %Second root
%Post-process: discard redundant or illegal solutions
T=[R1,R2,N11,N31];
T( any(~isfinite(T),2) | D<0 , : )=[]; %discard non-finite or complex solutions
[~,Iu]=uniquetol(T(:,1:2),tol,'ByRows',true); %discard repeat solutions (within tolerance)
T=num2cell(T(Iu,:),1);
[R1,R2,N11,N13]=deal(T{:});
figure
scatter3(R1,R2,N11,'.b');
xlabel('ROOT #1');
ylabel('ROOT #2');
zlabel('N11');
figure
scatter3(R1,R2,N13,'.b');
xlabel('ROOT #1');
ylabel('ROOT #2');
zlabel('N13');
カテゴリ
ヘルプ センター および File Exchange で Structural Mechanics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




