How can i optimize the code and connect the functions?
Show older comments
Hi everyone!
I've been dabbling with MatLab for the past three days and 've managed to write the following, working, code.
eta_l = xlsread('calculos.xlsx','Theoretical Predictions','S2');
eta_0 = xlsread('calculos.xlsx','Theoretical Predictions','S3');
l_c = xlsread('calculos.xlsx','Theoretical Predictions','P3');
sigma_f = xlsread('calculos.xlsx','Base Values','B3');
v_f = xlsread('calculos.xlsx','Burn','E23');
E_m = xlsread('calculos.xlsx','Base Values','D2');
E_f = xlsread('calculos.xlsx','Base Values','B2');
d = xlsread('calculos.xlsx','Base Values','B5');
%basically these functions y1 and y2 should be connected but i haven't been able to connect them
%plot of the Kelly-Tyson equation
x=linspace(-10,50);
idx = x < l_c;
y1=((eta_l.*eta_0.*((v_f.*sigma_f.*E_m)./(E_f.*d.*sqrt(3))).*x(idx))+((sigma_f.*E_m.*(1-v_f))./E_f));
y2=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x(~idx))+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
plot(x(idx),y1,x(~idx),y2);
ylim([0 1000]);
grid on
hold on
%basically these next two bits are the same and i would like to not repeat
%them and get the same to points in the plot
%plot of the 95% of the max of the Kelly-Tyson equation
syms x
f=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x)+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
maximus=limit(f,Inf);
eqn=f==0.95.*maximus;
S=solve(eqn,x);
plot(S,0.95.*maximus,'r*')
hold on
%plot of the 98% of the max of Kelly-Tyson equation
syms x
f1=(eta_l.*eta_0.*(((-sigma_f.*v_f.*l_c)./2).*(1./x)+(sigma_f.*v_f)))+(((sigma_f.*E_m)./E_f).*(1-v_f));
maximus1=limit(f1,Inf);
eqn1=f1==0.98.*maximus1;
S1=solve(eqn1,x);
plot(S1,0.98.*maximus1,'r*')
hold off
But... The last two bits are basically me writing them again and again. Is there a way where i can optimize the code so that i get a plot with the graphs of the functions connected - that is because they are connected in reality - and the points ploted but without having to write basically the same thing twice?
Thanks in advance!
Accepted Answer
More Answers (1)
Sulaymon Eshkabilov
on 14 Jul 2021
0 votes
One quick and easy suggestion is to employ readtable() instead of xlsread().
Categories
Find more on Solver Outputs and Iterative Display 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!


