How do I do both, integrate and derive a complex equation in a code using MATLAB App Designer?

Ok so I am designing an app for a class and the professor wants us to derive and integrate the equation by code. He does not want us to write it down and do it by hand. And well, after redooing the entire code, I am now struggling to find a way on how to derive and integrate the equation within the code in order for the app to function properly. According to MATLAB App Designer, I am getting an error since I have to be getting a possitive integer scalar. However, I have tried using abs command on diff to get a positive answer, but I get the same thing. I tried switching the position of E and Diff(v,e) but I get that E is an unknown variable. I havent eaten breakfast, im hungry, been working on this code since the morning... I am not sure what other thing i can do, I am running out of ideas. I just hope that no other errors pop out after and if I can fix this one. Can some expert on App Designer help me out with this please! I could really use the help! Please Help!

Answers (1)

It seems that you are treating diff() and int() as if their inputs are symbolic. However, from your code, it seems that inputs are numeric. You should use gradient() and trapz() to find the numerical derivative and integral
E = gradient(v, e)
a = trapz(e, v)

4 Comments

I apologize for the delayed reply. I had to eat something and I also took the oportunity to take a shower, so yeah. Also thanks for the help, It did help me advance...
Well that got me closer, Thank you for helping me out with that. Now I just have to get around that "Array indices must be positive or logical values" error.
I am providing as much info as I can since I cant trace my mistake...
Also I tried pinpointing that "line 335" since it mentions an error there, but the furthest it goes up to is 209.
I kept doing some tweaking and it turns out my code caught an std. Not sure which one is it, have to take it to a clinic to get tested xD.
Also I did pinpoint which line of code was getting the error. But not sure what it means when the error says "Array indices must be positive integers or logical values." So not sure how to proceed with it, ill continue to tweak with it until I find what works... Its just one teeny tiny erros that needs a fix. Well at least i hope its that.
I just found out that all of these were the error... not sure how to fix them...
Thankfully, it didn't catch an std. It was just a mistake in the testing process xD
The error is just happening because you are using 'e' for indexing. I see no reason for that. Write it like this
u = v;
w = E;
R = a;

Sign in to comment.

Asked:

on 8 May 2020

Commented:

on 9 May 2020

Community Treasure Hunt

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

Start Hunting!