-1

So I am creating an app to find a value based on several inputs but hit an error as one of the outputs won't show.

This is the app layout

1

The problem is the total cost section won't show the value when I clicked the calculate button. The 'Q Optimal' works just fine.

2

the formula associated with the button on the right side looks like this:

    dm=app.MinimumDemandEditField.Value;
    dM=app.MaximumDemandEditField.Value;
    tm=app.MinimumLeadTimeEditField.Value;
    tM=app.MaximumLeadTimeEditField.Value;
    r1=app.ReorderLevelEditField.Value;
    Et = 0.5*(tm+tM);
    vart = 1/12*(tM-tm)^2;
    Ed = 0.5*(dm+dM);
    vard = 1/12*(dM-dm)^2;
    ED = 1/4*(dm+dM)*(tm+tM);
    varD = 1/144*(3*(dm+dM)^2*(tM-tm)^2+3*(dM-dm)^2*(tm+tM)^2+(tM- 
    tm)^2*(dM-dm)^2);
    gt = 1/(tM-tm);
    fd = 1/(dM-dm);
    fD = 1/((dM-dm)*(tM-tm));
    f1=app.FixedCostEditField.Value;
    c1=app.VariableCostEditField.Value;
    h=app.HoldingCostEditField.Value;
    s=50*c1;
    app.ShortageCostEditField.Value = s
    A1=c1+(h/Ed)*(r1-ED);
    A2=fD*(r1*(tM-tm)*log(r1/(tM*dm))-(r1^2/dM)+(r1*tM)- 
    (r1*tm)*log((dM*tM)/r1)-Et);
    syms x;
    f=(x-r1)*fD;
    EB= int(f,r1,dM*tM);
    A3=Ed*f1+h*Ed*(fD*((r1^2*tm/2)-(dm*r1/2)*(tM^2-tm^2)+(dm^2/6)* 
    (tM^3-tm^3)-((r1^3/6*dM)-(dM*r1*tm^2/2)+(dM^2*tm^3/6)))+(fD/18)* 
    (tM^3-tm^3)*(dM^3-dm^3)-r1*ED+Ed*s*EB);
    Q=(1/h)*((Ed*(A1+h*A2-c1)+(h*(ED-r1))));
    Eoh=fD*((((r1^3*tM)/2)-(((dm*r1)/2)*(tM^2-tm^2))+(((dm^2)/6)* 
    (tM^3-tm^3))-((r1^3)/(6*dM))-((dM*r1*tm^2)/2)+((dM^2*tm^3)/6))+ 
    ((Q^2)/2*Ed)-(Q*ED/Ed)+((fD/(18*Ed))*((tM^3-tm^3)*(dM^3-dm^3)))+ 
    (Q*r1/Ed)-(r1*ED/Ed));
    TC= f1+c1*Q+h*Eoh+s*EB;
    app.QOptimalEditField.Value = Q
    app.TotalCostEditField.Value = TC

Running this gives the error:

3

I suspect the problem is with my integration process. Have I missed something or is there a better way to do this?

Thank you in advance Regards, Kevin Renard

Menol
  • 1,230
  • 21
  • 35
  • `app.QOptimalEditField.Value = num2str(Q)`, so you make it a character vector? – Ander Biguri Jan 10 '19 at 15:54
  • the code as I posted above is just `app.QOptimalEditField.Value = Q` @AnderBiguri – Kevin Renard Jan 10 '19 at 16:10
  • @Kevin Ander is suggesting you change that. The error states you need a character vector, you're using a number, make it a character vector using `num2str`!! – Wolfie Jan 10 '19 at 17:04
  • @KevinRenard yea I can read that, I am giving you the solution. – Ander Biguri Jan 10 '19 at 17:20
  • I'm sorry for my misunderstanding @AnderBiguri @Wolfie. When I add `num2str`, this gives error `Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 110) 'Value' must be a double scalar` in the `app.QOptimalEditField.Value = num2str (Q)` line – Kevin Renard Jan 11 '19 at 01:09

1 Answers1

1

I solved the problem as I noticed that the last error notification states that the input value must be a double scalar and the value of the integration process is not a double scalar, so I revised the integration code into:

syms x; f=(x-r1)*fD; EB= double(int(f,r1,dM*tM));

1