- The inner loop in your last for-loop should be over ‘j’, not ‘i’ again.
- You are trying to divide Aindex by Bindex elementwise, which is not correct for solving the system of equations.
- Lambda should be a vector, not a matrix since it represents the unknowns [x] in the system.
Can I complete a Gaussian equation using indeces?
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Howdy, all. 
I've attached all my code for a project involving the Panel Method for aero/hydrodynamics. Everything is working fine until I get to the last few lines (ignoring graphing code): 
Essentially, I started writing with indeces, which was probably a mistake. The Gaussian requires the matrices [A][x]=[b] be rearranged to give [x] = [A]\[b]. In my code, [A] is represented by Aindex(i,j) and [b] is Bindex(i,j). [x] would be Lambda(i,j), lines 42-43.
All values prior to executing Lambda(i,j) give correct values. I'm fairly certain the problem is trying to treat indeces like matrices. I've tried every division operator I know of (./, \, etc.) and I've tried inverting both indeces (shotgunning).
Is there a way I can compute the Gaussian without having to start from scratch with matrices? 
Final correct values for lambda are given: 

such that the correct value of lambda is the numerical term multiplied times 10. Appreciate your help!
0 Kommentare
Antworten (1)
  Shivam Lahoti
      
 am 29 Dez. 2023
        Hi Christopher, 
I can understand that you want to calculate Gaussian without having to start from scratch with matrices. There are some issues in your code that need to be addressed: 
Here is a corrected version of the last part of your code: 
% The system matrix and right-hand side vector 
Aindex = zeros(n, n); 
Bindex = zeros(n, 1); 
% Filling the system matrix Aindex and the vector Bindex 
for i= 1:n 
    for j= 1:n 
        Aindex(i,j)= I(i,j)/(2*pi); 
    end 
    Bindex(i)= (-Vinf)*cos(Beta(i)); 
end 
% Solving for the unknowns Lambda 
Lambda = Aindex\Bindex; 
% Calculating Check, V, and Pressure Coefficient 
Check = Lambda/Vinf; 
V = zeros(n, 1); 
PressCoeff = zeros(n, 1); 
for i= 1:n 
    sumJ = 0; 
    for j= 1:n 
        sumJ = sumJ + (Lambda(j)/(2*pi))*J(i,j); 
    end 
    V(i) = sumJ + (Vinf*sin(Beta(i))); 
    PressCoeff(i) = 1 - ((V(i)/Vinf)^2); 
end 
% Plotting 
plot(PressCoeff,'b') 
set(gca,'XTick',0:pi/2:2*pi)  
set(gca,'XTickLabel',{'0','pi/2','pi','3*pi/2','2*pi'}) 
This corrected code first constructs the system matrix Aindex and the right-hand side vector Bindex. Then, it solves for Lambda using the backslash operator. After that, it calculates the velocity V and pressure coefficient PressCoeff using the computed Lambda. 
I hope this was helpful. 
Regards,  
Shivam Lahoti. 
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

