Can anyone identify the error? and correct it.

조회 수: 4 (최근 30일)
Sobaan
Sobaan 2022년 11월 23일
편집: Jan 2022년 11월 23일
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
Jan
Jan 2022년 11월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2022년 11월 23일
편집: Jan 2022년 11월 23일
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by