Clear Filters
Clear Filters

How do i vectorise a function created by spline

1 view (last 30 days)
I have the following functions, created with the help of spline
function c = consumption(v)
load('elbilTesla.mat');
if any(v < speed_kmph(1)) || any(v > speed_kmph(end))
error(['Hastigheten måste vara inom intervallet ', num2str(speed_kmph(1)), ' till ', num2str(speed_kmph(end)), '!']);
else
c = interp1(speed_kmph, consumption_Whpkm, v, 'spline');
end
end
function E = total_consumption(x, route)
load(route);
if any(x < distanceA_km(1)) || any(x > distanceA_km(end))
error(['Sträckan måste vara inom intervallet ', num2str(distance_km(1)), ' till ', num2str(distance_km(end)), '!']);
else
v=interp1(distanceA_km, speedA_kmph, x, 'spline');
E=integral(@(x) consumption(v),0,x,'ArrayValued',true);
end
end
i would like to plot this function and use fzero to input a vector in 'x' and not a single value.
How does one vectorise a function created by spline?
  1 Comment
Maximilian Jatzkowski
Maximilian Jatzkowski on 7 Jan 2019
Edited: Jan on 7 Jan 2019
i mistyped, i want to use fzero and therefore need to be able to input a vector into the function

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!