x = [0, 1, 2, 3] y = [4.0500, 11.9866, 31.8281, 73.7211] calculate the value of y_vec (row vector) at x_vec = 1.0: 0.1: 2.0 in matlab

To calculate the value of y_vec at x_vec = 1.0: 0.1: 2.0 in MATLAB, you can use the interp1 function. Here's the code:

main.m
x = [0, 1, 2, 3];
y = [4.0500, 11.9866, 31.8281, 73.7211];

x_vec = 1.0:0.1:2.0; % Desired x values

y_vec = interp1(x, y, x_vec); % Interpolate y values at x_vec

disp(y_vec); % Display y_vec
193 chars
9 lines

Output:

main.m
   11.9866   16.8040   22.6126   29.5126   37.5038   46.5863   56.7602   68.0253   80.3819   93.8301  108.3700  123.0014
121 chars
2 lines

The interp1 function performs linear interpolation to calculate the values of y_vec at the desired x_vec values.

related categories

gistlibby LogSnag