Undefined function or variable 'solv'.
Show older comments
I am using ode45 to solve 32 coupled ODEs. I am not used to matlab, so it could be a very simple fix, but when attempting to solve the system, I get the error "Undefined function or variable 'solv' ," where 'solv' is my function.
function diff = solv(t,x)
Vex = x(1);
Vatt_hi= x(2);
Vatt_lo= x(3);
Ven= x(4);
Vp_cyt= x(5);
Vp_nuc= x(6);
Rc= x(7);
Rv= x(8);
Rc_rdrp= x(9);
Rv_rdrp= x(10);
Cp= x(11);
Vpnuc_m1= x(12);
Vpcyt_m1= x(13);
Rm_1= x(14);
Rm_2= x(15);
Rm_3= x(16);
Rm_4= x(17);
Rm_5= x(18);
Rm_6= x(19);
Rm_7= x(20);
Rm_8= x(21);
Ppb1= x(22);
Ppb2= x(23);
Ppa= x(24);
Prdrp= x(25);
Pnp= x(26);
Pm1= x(27);
Pnep= x(28);
Pha= x(29);
Pna= x(30);
Pm2= x(31);
vrel = x(32);
diff(1,1) = kdis_hi * Vatt_hi + kdis_lo * Vatt_lo - (katt_hi * (btot_hi - Vatt_hi) + katt_lo * (btot_lo - Vatt_lo)) * Vex;
diff(2,1) = katt_hi * (btot_hi - Vatt_hi) * Vex - (kdis_hi + ken) * Vatt_hi;
diff(3,1) = katt_lo * (btot_lo - Vatt_lo) * Vex - (kdis_lo + ken) * Vatt_lo;
diff(4,1) = ken * (Vatt_hi + Vatt_lo) - (kfus + kdeg_Ven) * Ven;
diff(5,1) = 8 * kfus * Ven - kimp * Vp_cyt;
diff(6,1) = kimp * Vp_cyt + kbind_np * Pnp * Rv_rdrp - (kbind_m1 * Pm1 + kdeg_rnp) * Vp_nuc;
diff(7,1) = ksyn_c * Vp_nuc - kbind_rdrp * Prdrp * Rc - kdeg_r * Rc;
diff(8,1) = ksyn_v * Cp - kbind_rdrp * Prdrp * Rv - kdeg_r * Rv;
diff(9,1) = kbind_rdrp * Prdrp * Rc - kbind_np * Pnp * Rc_rdrp - kdeg_rrdrp * Rc_rdrp;
diff(10,1) = kbind_rdrp * Prdrp * Rv - kbind_np * Pnp * Rv_rdrp - kdeg_rrdrp * Rv_rdrp;
diff(11,1) = kbind_np * Pnp * Rc_rdrp - kdeg_rnp * Cp;
diff(12,1) = kbind_m1 * Pm1 * Vp_nuc - (kexp * Pnep + kdeg_rnp) * Vpnuc_m1;
diff(13,1) = kexp * Pnep * Vpnuc_m1 - 8 * vrel - kdeg_rnp * Vpcyt_m1;
diff(14,1) = (ksyn_m / l1) * (Vp_nuc / 8) - kdeg_m * Rm_1;
diff(15,1) = (ksyn_m / l2) * (Vp_nuc / 8) - kdeg_m * Rm_2;
diff(16,1) = (ksyn_m / l3) * (Vp_nuc / 8) - kdeg_m * Rm_3;
diff(17,1) = (ksyn_m / l4) * (Vp_nuc / 8) - kdeg_m * Rm_4;
diff(18,1) = (ksyn_m / l5) * (Vp_nuc / 8) - kdeg_m * Rm_5;
diff(19,1) = (ksyn_m / l6) * (Vp_nuc / 8) - kdeg_m * Rm_6;
diff(20,1) = (ksyn_m / l7) * (Vp_nuc / 8) - kdeg_m * Rm_7;
diff(21,1) = (ksyn_m / l8) * (Vp_nuc / 8) - kdeg_m * Rm_8;
diff(22,1) = (ksyn_p / drib) * Rm_2 - krdrp * Ppb1 * Ppb2 * Ppa;
diff(23,1) = (ksyn_p / drib) * Rm_1 - krdrp * Ppb1 * Ppb2 * Ppa;
diff(24,1) = (ksyn_p / drib) * Rm_3 - krdrp * Ppb1 * Ppb2 * Ppa;
diff(25,1) = krdrp * Ppb1 * Ppb2 * Ppa - kbind_rdrp * Prdrp * (Rv + x(7)) - (n_prdrp - 8) * vrel;
diff(26,1) = (ksyn_p / drib) * Rm_5 - (lv / nnuc_np) * kbind_np * Pnp * (Rc_rdrp + Rv_rdrp) - (n_pnp - 8 * (lv / nnuc_np)) * vrel;
diff(27,1) = (ksyn_p / drib)*(1 - f_spl7) * Rm_7 - (lv / nnuc_m1) * kbind_m1 * x(6) - (n_pm1 - 8 * (lv / nnuc_m1)) * vrel;
diff(28,1) = (ksyn_p / drib) * f_spl8 * Rm_8 - (lv / nnuc_nep) * kexp * Pnep * Vpnuc_m1 - (n_pnep - 8 * (lv / nnuc_nep)) * vrel;
diff(29,1) = (ksyn_p / drib) * Rm_4 - n_pha * vrel;
diff(30,1) = (ksyn_p / drib) * Rm_6 - n_pna * vrel;
diff(31,1) = (ksyn_p / drib) * f_spl7 * Rm_7 - n_pm2 * vrel;
diff(32,1) = krel * Vpcyt_m1 * ((Prdrp/(Prdrp + kv_rel * n_prdrp)) * (Pha/(Pha + kv_rel * n_pha)) * (Pnp/(Pnp + kv_rel * n_pnp)) * (Pna/(Pna + kv_rel * n_pna)) * (Pm1/(Pm1 + kv_rel * n_pm1)) * (Pm2/(Pm2 + kv_rel * n_pm1)) * (Pnep/(Pnep + kv_rel * n_pnep)));
end
% in another file
t = linspace(0,60);
x = [10 100 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
[time,xsol] = ode45(@solv,t,x);
Answers (1)
Star Strider
on 17 Sep 2020
0 votes
Where did you save it?
You must save it to a directory or your MATLAB user path, and MATLAB has to know that directory exists.
3 Comments
Bill Bastian
on 17 Sep 2020
Steven Lord
on 17 Sep 2020
Is your solv function in a file named solv.m or is the file under a different name? The recommendation is that the main function in a file share its name with the file. If they do differ, MATLAB will know the function by the file name.
% if this is in a file timesthree.m you will need to call it like:
%
% y = timesthree(5) % y is 10
function y = timestwo(x)
y = 2*x;
end
Bill Bastian
on 17 Sep 2020
Categories
Find more on Startup and Shutdown 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!