Can anyone identify the error? and correct it.

1 Ansicht (letzte 30 Tage)
Sobaan
Sobaan am 23 Nov. 2022
Bearbeitet: Jan am 23 Nov. 2022
clc;
clear all;
close all;
%Newtons Forawrd Difference Formula Matlab Program
v=[8 10 12 14 16];%Inputting values of v
Iv=[1000 1900 3250 5400 8950]; %Inputting values
dt= zeros (5,6); %function
for i=1:5 dt(i,1)=v(i); %for loop
dt (i,2)=Iv(i);
end
for j=3:6
for i=1:n
dt(i,j)=dt(i+1,j-1)-dt(i,j-1)
end
n=n-1;
end
h=v(2)-v(1)%finding the value of h
vp=9;%definig the values of vp
for i=1:4
q=(vp-v(i))/h; %calculating number of intervals
if (q>0&q<1)
p=q;
end
end
p
1=vp-(p*h);f
for i=1:4
if(1=v(i))
r=1;
end
end%calculating difference value of I
I0=Iv(r);
I01=dt(r,3);
I02=dt(r,(3+1));
I03=dt((r),(3+2));
I04=dt((r),(3+3));
% using the forward interpolation formula
Ip=(I0)+((p*I01)+(p*(P-1)I02)/(2))+((P(p-1)(p-2)*I03)/(6))+((p(p-1)(p-2)(p-3)*I04)/(24))
  1 Kommentar
Jan
Jan am 23 Nov. 2022
It is useful to find the cause of an error to know, what you consider as error. You do have this important information available already, so please share it with the readers instead of letting them guess, what the problem is.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 23 Nov. 2022
Bearbeitet: Jan am 23 Nov. 2022
Avoid an overkill of parentheses:
Ip=(I0)+((p*I01)+(p*(P-1)I02)/(2))+((P(p-1)(p-2)*I03)/(6))+((p(p-1)(p-2)(p-3)*I04)/(24))
% ^^^^^^^ ? ^^^^^^^^^^^^ ? ^^^^^^^^^^^^^^^^ ???
This is hard to read and even no valid Matlab syntax anymore. Maybe you mean:
Ip = I0 + (p*I01 + p*(P-1)*I02 / 2 + P*(p-1)*(p-2)*I03 / 6 + p*(p-1)*(p-2)*(p-3)*I04 / 24
When I run your code in the forum (simply press the green triangle) I get a clear error message here:
p
1=vp-(p*h);f
The assignment by = is not possible, if the left side is a constant. Maybe you have pressed Enter and it should be:
p1=vp-(p*h); % f ???
This is not meaningful also:
if(1=v(i))
The operator for the comparison is ==, while = is an assignment. You cannot assign the value of v(i) to the number 1.
A general hint: Prefer useful comments:
vp=9;%definig the values of vp
Of course the value of vp is defined, but why is it set to 9?
for i=1:5 dt(i,1)=v(i); %for loop
Yes, this is a for loop, but you do not need a comment to mention this.

Kategorien

Mehr zu Get Started with MATLAB 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!

Translated by