MATLAB Answers

GRAM-SCHMIDT FUNCTION IS NOT GIVING CORRECT VALUES

4 views (last 30 days)
nikhil mahar
nikhil mahar on 8 May 2021
Edited: nikhil mahar on 9 May 2021
Hello everyone,
I am trying to obtain equations of phi. I am getting wrong value of phi{3}. There is somthing wrong, which I am unable to figure out.
here is code:
clc
clear all;
initial_function=@(x,y)x.^2;
m=3;
for i=1:m;
r=floor(sqrt(i-1));
t=i-1-r.^2;
if t/2==0;
s=t/2;
fm{i}=@(x,y)(x.^r).*(y.^s)
else
s=(t-1)/2;
fm{i}=@(x,y)(x.^s).*(y.^r);
end
end
for i=1:1
phi{i}=@(x,y)fm{1}(x,y).*initial_function(x,y);
end
xmin=@(y) y;
syms x y;
for i=2:m
phi{i}=@(x,y)fm{i}(x,y).*phi{1}(x,y);
for j=1:i-1;
a{i}{j} = integral2(@(y,x)fm{i}(x,y).*phi{1}(x,y).*phi{j}(x,y),0,1,xmin,1)./integral2(@(y,x)phi{j}(x,y).*phi{j}(x,y),0,1,xmin,1);
phi{i}=@(x,y)phi{i}(x,y)-a{i}{j}.*phi{j}(x,y);
end
phi1{i}=phi{i}(x,y);
end
phi{1} and phi{2} are correct.
phi{3} which i am getting from matlab is: x^2*y - (29645651611899925216907*x^2)/81129638414606681695789005144064 - (4503599623397961*x^3)/9007199254740992
while correct phi{3} is: x^2*y- 3.328*10^(-3) - 0.504x^3.
I shall be very thankful if somone can help.

Answers (1)

Scott MacKenzie
Scott MacKenzie on 8 May 2021
It would be helpful if you posted your code as MATLAB code, not question text.
  2 Comments
nikhil mahar
nikhil mahar on 8 May 2021
these are the functions(phi) which i am trying to get from first 2 formule.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!