Interp1 error VqLite = F(Xqcol)

3 views (last 30 days)
Deanna
Deanna on 16 Feb 2023
Answered: Aditya Srikar on 2 Mar 2023
clc;clear;
Filename= 'Homework 2 Dropsonde Updated2.xlsx';
T=readtable(Filename);
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
T.AirTemp= T.AirTemp + 273.15;
%Humidity Graph After Converson
R=T.RelHumid;
Temp= T.AirTemp;
p=T.AirPress;
A=[];
for i=1:length(R)
Aval=6.12*(R(i)/100)*(exp((17.67*(Temp(i)-273.15))/(Temp(i)-29.65)))*(p(i)/1013.25);
A(end+1) = Aval;
end
A= A';
%figure(3)
%plot(A,T.GeopotenAltitude)
%Question 1a
N=[];
for i=1:length(Temp)
Nval= (77.6/Temp(i))*(p(i)+ ((4810*A(i))/Temp(i)));
N(end+1)= Nval;
end
N= N';
% figure(1)
% plot(N,T.GeopotenAltitude)
% title('ECE 6735 HW2 Problem 1a');
% xlabel('Refractivity (mbar)');
% ylabel('Altitude (m)');
%Question 1c
alt= T.GeopotenAltitude;
n0=interp1(alt,N,0);
angle= deg2rad(0.2);
deltaX= 0.2;
h=0;
x=0;
Re= 6371 *10^3;
while h< 1000
alt
N
h
nh=interp1(alt,N,h);
h= h+ deltaX* sqrt((angle^2)+(2*(nh+(h/Re)-n0)));
x=x+deltaX;
end
alt = 376×1
1.0e+03 * 2.6328 2.6251 2.6182 2.6129 2.6068 2.6008 2.5943 2.5878 2.5821 2.5768
N = 376×1
236.5111 236.6743 236.8167 236.9778 237.3261 237.4599 237.7228 238.1719 238.5314 238.8193
h = 0
alt = 376×1
1.0e+03 * 2.6328 2.6251 2.6182 2.6129 2.6068 2.6008 2.5943 2.5878 2.5821 2.5768
N = 376×1
236.5111 236.6743 236.8167 236.9778 237.3261 237.4599 237.7228 238.1719 238.5314 238.8193
h = 6.9813e-04
alt = 376×1
1.0e+03 * 2.6328 2.6251 2.6182 2.6129 2.6068 2.6008 2.5943 2.5878 2.5821 2.5768
N = 376×1
236.5111 236.6743 236.8167 236.9778 237.3261 237.4599 237.7228 238.1719 238.5314 238.8193
h = 0.0007 + 0.0011i
Error using matlab.internal.math.interp1
Input coordinates must be real.

Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
So I am trying to create a code that takes in data from an exel and then uses the interp1 function to find the N value at that given height. I set h=0 sicne I am starting on the ground but when I use nh=interp1(alt, N, h) I get the error. When I use n0= interp1(alt, N, 0) I get an actual value.
I didnt think that using a variable instead of an actual value would matter if the variable had a number assigned to it.
Here is the error message:
Error in interp1 (line 152)
VqLite = F(Xqcol);
Error in ECE_6375_HW2_1 (line 45)
nh=interp1(alt,N,h);
  5 Comments
Torsten
Torsten on 16 Feb 2023
As you can see above, h in your code - defined as h= h+ deltaX* sqrt((angle^2)+(2*(nh+(h/Re)-n0))); - becomes complex-valued (most probably because (angle^2)+(2*(nh+(h/Re)-n0)) becomes negative).
Deanna
Deanna on 16 Feb 2023
Thank you! I did not catch that and thought there was something wrong with the variable.

Sign in to comment.

Accepted Answer

Aditya Srikar
Aditya Srikar on 2 Mar 2023
Hi Deanna
Consider this statement in while-loop
h= h+ deltaX* sqrt((angle^2)+(2*(nh+(h/Re)-n0)));
The value angle^2 is always non-negative.
But if 2*(nh+(h/Re) < n0, then (2*(nh+(h/Re)-n0) becomes negative.
When (2*(nh+(h/Re)-n0) is negative and (angle^2)+(2*(nh+(h/Re)-n0)) also becomes negative, then the whole expression sqrt((angle^2)+(2*(nh+(h/Re)-n0))) would not be having any real roots and it will result in imaginary values as roots of the equation.
That’s the reason why you are getting an error
Error using matlab.internal.math.interp1
Input coordinates must be real.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!