Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. using matlab code in vb environment

using matlab code in vb environment

Scheduled Pinned Locked Moved COM
helpquestionworkspace
13 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    freesun
    wrote on last edited by
    #1

    Hi ..i am currently working on one of my Vb project and sicne i am not so proffesional with programming i need little help..Well my quesiton is that need to solve some equations numerically adn since as far as i know in vb we are not able to perform numerical calculations such as those Runge-Kutta,Newton Raphson etc.( here if i am wrong please correct me may be vb can handle such problems !!!) so in my problem user is asked to input some numbers so i want to build such kind of code in matlab and THEN here my question comes how can i translate my matlab code into Vb forms and after translation does this code again ask the user required input datas as it does in matlab...if yes can anyone help me about this problem.Thank you very much i hope my question is clear to all... i look forward to hearing from you enversun

    V 1 Reply Last reply
    0
    • F freesun

      Hi ..i am currently working on one of my Vb project and sicne i am not so proffesional with programming i need little help..Well my quesiton is that need to solve some equations numerically adn since as far as i know in vb we are not able to perform numerical calculations such as those Runge-Kutta,Newton Raphson etc.( here if i am wrong please correct me may be vb can handle such problems !!!) so in my problem user is asked to input some numbers so i want to build such kind of code in matlab and THEN here my question comes how can i translate my matlab code into Vb forms and after translation does this code again ask the user required input datas as it does in matlab...if yes can anyone help me about this problem.Thank you very much i hope my question is clear to all... i look forward to hearing from you enversun

      V Offline
      V Offline
      Vibhash Jha
      wrote on last edited by
      #2

      i thnik matlab has GUI toolbox exactly like VB(i mena textbook,dialog ,etc.) . So why do want it to convert it to VB forms?? tell me if I cudn't understand U?? cheers vibhash

      F 1 Reply Last reply
      0
      • V Vibhash Jha

        i thnik matlab has GUI toolbox exactly like VB(i mena textbook,dialog ,etc.) . So why do want it to convert it to VB forms?? tell me if I cudn't understand U?? cheers vibhash

        F Offline
        F Offline
        freesun
        wrote on last edited by
        #3

        Yes i know but started to build my project in Vb environment and now since some numerical techniques i have to use and cant do this by Vb by using matlab i want to solve those numerical problems and eport them from matlab to my Vb project that i have already build in Vb..So since the time is short i cant do all again by matlab GUI.. .... My second question is that is there a way to export matlab GUI to Vb as a Vb new form maybe it is possible.. or does it work if i copy and paste my symbollic formualtions ( such as numerical integrations..differantiations etc..) solved by matlab in to VB code page.. may be this is the alternative way but does it work?

        V 1 Reply Last reply
        0
        • F freesun

          Yes i know but started to build my project in Vb environment and now since some numerical techniques i have to use and cant do this by Vb by using matlab i want to solve those numerical problems and eport them from matlab to my Vb project that i have already build in Vb..So since the time is short i cant do all again by matlab GUI.. .... My second question is that is there a way to export matlab GUI to Vb as a Vb new form maybe it is possible.. or does it work if i copy and paste my symbollic formualtions ( such as numerical integrations..differantiations etc..) solved by matlab in to VB code page.. may be this is the alternative way but does it work?

          V Offline
          V Offline
          Vibhash Jha
          wrote on last edited by
          #4

          I will give u a wild advice which you may not like but worked for me many of the time.. just for the sake of completing your project.. 1)You can create a output file based on MATLAB numerical datas and try to read that file In VB..only one basic problem.. if ur num datas are too dynamic.. ur refresh rate thru VB code should be fast enough to give u the desired behaviour.. may be u have the compromise in performnace but still works.. 2) i am not sure but i do think there will be OCX controls provided by MATLAB (u can serach in VB toolbars) to import its GUI in ur VB forms.. in that case i think ur life will be pretty easy but still u have to juggle ur head to understand the new APIs.. if u can take this much pain.. the i think it will perfectly okay..it will help you in future projects even.. 3) copying ur formualtions is not a gud ideas as VB will trim ur calcualtions datas to a large extent and u will get roudoff erro.s so better leave these calculation part to MATLAB (they have much sophisticated algorithms to support this).. but if u think that u can work without much accuracy.. u can apply this technique too..but again not advisable.. cheers vibhash Bangalore,INDIA

          F 1 Reply Last reply
          0
          • V Vibhash Jha

            I will give u a wild advice which you may not like but worked for me many of the time.. just for the sake of completing your project.. 1)You can create a output file based on MATLAB numerical datas and try to read that file In VB..only one basic problem.. if ur num datas are too dynamic.. ur refresh rate thru VB code should be fast enough to give u the desired behaviour.. may be u have the compromise in performnace but still works.. 2) i am not sure but i do think there will be OCX controls provided by MATLAB (u can serach in VB toolbars) to import its GUI in ur VB forms.. in that case i think ur life will be pretty easy but still u have to juggle ur head to understand the new APIs.. if u can take this much pain.. the i think it will perfectly okay..it will help you in future projects even.. 3) copying ur formualtions is not a gud ideas as VB will trim ur calcualtions datas to a large extent and u will get roudoff erro.s so better leave these calculation part to MATLAB (they have much sophisticated algorithms to support this).. but if u think that u can work without much accuracy.. u can apply this technique too..but again not advisable.. cheers vibhash Bangalore,INDIA

            F Offline
            F Offline
            freesun
            wrote on last edited by
            #5

            while i was trying the 3rd one you mentioned i have come accross a new problem as i mentioned below dSdFF=(sqrt((2+4*r)*(1+r)/(2*r+1))+tan(FF))*(dKhotFF)+(2*RR*sin(FF)*tan(FF)+h*(sec(FF))^2+2*RR*cos(FF)+2*RR*sqrt((2+4*r)*(1+r)/(2*r+1))*sin(FF))*Khot/h dSdFF = -2*(((2+4*r)*(1+r)/(1+2*r))^(1/2)+tan(FF))*((4/3+2/3*r)/(2+4*r))^(1/2)*A1*(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))^n*n*((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)/(H2+2*RR*(1-cos(FF)))*RR*sin(FF)/(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))+(2*RR*sin(FF)*tan(FF)+(H2+2*RR*(1-cos(FF)))*sec(FF)^2+2*RR*cos(FF)+2*RR*((2+4*r)*(1+r)/(1+2*r))^(1/2)*sin(FF))*((4/3+2/3*r)/(2+4*r))^(1/2)*(A1*(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))^n-A2*e^m)/(H2+2*RR*(1-cos(FF))) >> intdSdFF=int(dSdFF,FF) Warning: Explicit integral could not be found. > In C:\MATLAB6p5\toolbox\symbolic\@sym\int.m at line 58 i have a differantial equ'n such as dS/dFF and i want to integrate w.r.t FF to get S function but it does nt work gave error as above.. do you have an idea ..please help :(

            V 1 Reply Last reply
            0
            • F freesun

              while i was trying the 3rd one you mentioned i have come accross a new problem as i mentioned below dSdFF=(sqrt((2+4*r)*(1+r)/(2*r+1))+tan(FF))*(dKhotFF)+(2*RR*sin(FF)*tan(FF)+h*(sec(FF))^2+2*RR*cos(FF)+2*RR*sqrt((2+4*r)*(1+r)/(2*r+1))*sin(FF))*Khot/h dSdFF = -2*(((2+4*r)*(1+r)/(1+2*r))^(1/2)+tan(FF))*((4/3+2/3*r)/(2+4*r))^(1/2)*A1*(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))^n*n*((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)/(H2+2*RR*(1-cos(FF)))*RR*sin(FF)/(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))+(2*RR*sin(FF)*tan(FF)+(H2+2*RR*(1-cos(FF)))*sec(FF)^2+2*RR*cos(FF)+2*RR*((2+4*r)*(1+r)/(1+2*r))^(1/2)*sin(FF))*((4/3+2/3*r)/(2+4*r))^(1/2)*(A1*(B1+((4/3+2/3*r)*(1+r)/(1+2*r))^(1/2)*log(H1/(H2+2*RR*(1-cos(FF)))))^n-A2*e^m)/(H2+2*RR*(1-cos(FF))) >> intdSdFF=int(dSdFF,FF) Warning: Explicit integral could not be found. > In C:\MATLAB6p5\toolbox\symbolic\@sym\int.m at line 58 i have a differantial equ'n such as dS/dFF and i want to integrate w.r.t FF to get S function but it does nt work gave error as above.. do you have an idea ..please help :(

              V Offline
              V Offline
              Vibhash Jha
              wrote on last edited by
              #6

              ya thta's true.. it is not always possible for the matlab kernel to find the explicit integral.. there can be many posiblities.. 1) try subsituting the values of the constants(like r,h...) used in your function. 2) or you have to provide range of the integration like int(f,start,end) 3) if still it doens't work , may be you have to go for numerical integration.. try quad.. or simply double(int(f,start,end))..(internally double does the numerical integration for you..) it's possibly that if you provide the same function in MATCAD/mathematica , you will get a solution as it internally does the numeraical integration(ofcourse range has to be provided..) cheers vibhash B'lore,INDIA

              F 1 Reply Last reply
              0
              • V Vibhash Jha

                ya thta's true.. it is not always possible for the matlab kernel to find the explicit integral.. there can be many posiblities.. 1) try subsituting the values of the constants(like r,h...) used in your function. 2) or you have to provide range of the integration like int(f,start,end) 3) if still it doens't work , may be you have to go for numerical integration.. try quad.. or simply double(int(f,start,end))..(internally double does the numerical integration for you..) it's possibly that if you provide the same function in MATCAD/mathematica , you will get a solution as it internally does the numeraical integration(ofcourse range has to be provided..) cheers vibhash B'lore,INDIA

                F Offline
                F Offline
                freesun
                wrote on last edited by
                #7

                hi firstly i really thank you for your valuable suggestions and comment but i still could nt solved that equation i wonder if you help me simultaneously from net...if you ok for you we can get contact each other .. k=g(x) i have (dS/dx)=f(S,x,dk/dx) type equation and if you have experinced to solve such problemms please help me my aim is to find P=int(S,x)....

                V 1 Reply Last reply
                0
                • F freesun

                  hi firstly i really thank you for your valuable suggestions and comment but i still could nt solved that equation i wonder if you help me simultaneously from net...if you ok for you we can get contact each other .. k=g(x) i have (dS/dx)=f(S,x,dk/dx) type equation and if you have experinced to solve such problemms please help me my aim is to find P=int(S,x)....

                  V Offline
                  V Offline
                  Vibhash Jha
                  wrote on last edited by
                  #8

                  I have understood the problem.. i think you cudn't understand my argument.. I will try explaining again.. Suppose f(x) = (1/2 + cos(x) ) int(f,x) = x/2 +sin(x) .. it has a indefinite integral solution.. but say if f(x) = sqrt(1/3 + log(sin(x^(1/3))) int(f,x) will show error .. as it is not possible for the integral to solve indefinitely. In this case , we have to go to numerical integration.. so, we have to try double(int(f,x,lb,ub)) double --> for numerical integration lb,ub - >lower and upper bounds.. in this case you will get a definite solution.. I think your function is also too complex which can't be solved definitely.. so you have to numerical integration.. there is no other choice.. can you tell me the upper and lower bounds in which you want to integrate the functions??? may be i can help you.. i could i have given you the results but currently i don't have MATLAB installed in my PC... i think i am clear now.. cheers vibhash B'lore, INDIA

                  F 2 Replies Last reply
                  0
                  • V Vibhash Jha

                    I have understood the problem.. i think you cudn't understand my argument.. I will try explaining again.. Suppose f(x) = (1/2 + cos(x) ) int(f,x) = x/2 +sin(x) .. it has a indefinite integral solution.. but say if f(x) = sqrt(1/3 + log(sin(x^(1/3))) int(f,x) will show error .. as it is not possible for the integral to solve indefinitely. In this case , we have to go to numerical integration.. so, we have to try double(int(f,x,lb,ub)) double --> for numerical integration lb,ub - >lower and upper bounds.. in this case you will get a definite solution.. I think your function is also too complex which can't be solved definitely.. so you have to numerical integration.. there is no other choice.. can you tell me the upper and lower bounds in which you want to integrate the functions??? may be i can help you.. i could i have given you the results but currently i don't have MATLAB installed in my PC... i think i am clear now.. cheers vibhash B'lore, INDIA

                    F Offline
                    F Offline
                    freesun
                    wrote on last edited by
                    #9

                    hi ; yes i understood you..and you are right there is no other choice and i have to make numerical integraiton.Well since this problem will be yielded outputs from Vb environment according to the user inputs i have to make those numerical calcualtions in Vb environment ..i wsih i could show those function but how maybe i will take the picutre of them from my web cam and show you maybe i can explain it better...you know i know i can apply some numerical techniques to some simple functions but i had never experinced with such hard function so it challenges me any way ..well please correct me where i am wrong, if i use Runge Kutta, one of numerical integration technique,to solve dS/dx which has initial S at x=0 (lower bound) (S initial is known) by selecting step size h =0.1,to the final value of x=10 (upper bound) i get 100 S values....now i want to use this values in another integration (P=int(S,x)) at this time to obtain another P value which depends on those S values so at the end i have S1 S2 .....S100 (100 S values) and x1 x2 ....(incrementing with h =0.1) as 0 0.1 0.2 0.3......10 (100 x values) how can make nurmical integration with above values to obtain final P value... i hope you understand me .i can really understand you clearly...i hope i will solve this problem with your valuable help.. and if you want i can send you a picture of functions taken by web cam this can help you to understand my question well ... last quesiton does it seems that i cane make those calculations with Vb ? thanks in advance..

                    V 1 Reply Last reply
                    0
                    • F freesun

                      hi ; yes i understood you..and you are right there is no other choice and i have to make numerical integraiton.Well since this problem will be yielded outputs from Vb environment according to the user inputs i have to make those numerical calcualtions in Vb environment ..i wsih i could show those function but how maybe i will take the picutre of them from my web cam and show you maybe i can explain it better...you know i know i can apply some numerical techniques to some simple functions but i had never experinced with such hard function so it challenges me any way ..well please correct me where i am wrong, if i use Runge Kutta, one of numerical integration technique,to solve dS/dx which has initial S at x=0 (lower bound) (S initial is known) by selecting step size h =0.1,to the final value of x=10 (upper bound) i get 100 S values....now i want to use this values in another integration (P=int(S,x)) at this time to obtain another P value which depends on those S values so at the end i have S1 S2 .....S100 (100 S values) and x1 x2 ....(incrementing with h =0.1) as 0 0.1 0.2 0.3......10 (100 x values) how can make nurmical integration with above values to obtain final P value... i hope you understand me .i can really understand you clearly...i hope i will solve this problem with your valuable help.. and if you want i can send you a picture of functions taken by web cam this can help you to understand my question well ... last quesiton does it seems that i cane make those calculations with Vb ? thanks in advance..

                      V Offline
                      V Offline
                      Vibhash Jha
                      wrote on last edited by
                      #10

                      i think i understand u little.. but still i would like to have some snapshots and clear picture from beginning.. that would help me to understand better..

                      1 Reply Last reply
                      0
                      • V Vibhash Jha

                        I have understood the problem.. i think you cudn't understand my argument.. I will try explaining again.. Suppose f(x) = (1/2 + cos(x) ) int(f,x) = x/2 +sin(x) .. it has a indefinite integral solution.. but say if f(x) = sqrt(1/3 + log(sin(x^(1/3))) int(f,x) will show error .. as it is not possible for the integral to solve indefinitely. In this case , we have to go to numerical integration.. so, we have to try double(int(f,x,lb,ub)) double --> for numerical integration lb,ub - >lower and upper bounds.. in this case you will get a definite solution.. I think your function is also too complex which can't be solved definitely.. so you have to numerical integration.. there is no other choice.. can you tell me the upper and lower bounds in which you want to integrate the functions??? may be i can help you.. i could i have given you the results but currently i don't have MATLAB installed in my PC... i think i am clear now.. cheers vibhash B'lore, INDIA

                        F Offline
                        F Offline
                        freesun
                        wrote on last edited by
                        #11

                        hi i wanted to add this as i looked from the numerical integration book while x=[x1 x2 x3 ..etc] and S=[S1 S2 S3 .....] matlab can take integration with trapz(x,S) does it give accurate results

                        V 1 Reply Last reply
                        0
                        • F freesun

                          hi i wanted to add this as i looked from the numerical integration book while x=[x1 x2 x3 ..etc] and S=[S1 S2 S3 .....] matlab can take integration with trapz(x,S) does it give accurate results

                          V Offline
                          V Offline
                          Vibhash Jha
                          wrote on last edited by
                          #12

                          trapz gives the numerical result using trapezoidal method.. in your case. if s are functions of x.. it will be give you a range of values.. is this what you are looking for?? exmaple x = [0:pi/100:pi] what is essentially ( 0,pi/100,2pi/100,.....pi) y = sin(x) trapz(x,y) integrate y wrt x ang gives u a single value..but if y itself is aset of numbers.. i think output itself will be a set og umbers.. i think u can check this with a small example.. Are you trying to evaluate some double integration kind of thing???

                          F 1 Reply Last reply
                          0
                          • V Vibhash Jha

                            trapz gives the numerical result using trapezoidal method.. in your case. if s are functions of x.. it will be give you a range of values.. is this what you are looking for?? exmaple x = [0:pi/100:pi] what is essentially ( 0,pi/100,2pi/100,.....pi) y = sin(x) trapz(x,y) integrate y wrt x ang gives u a single value..but if y itself is aset of numbers.. i think output itself will be a set og umbers.. i think u can check this with a small example.. Are you trying to evaluate some double integration kind of thing???

                            F Offline
                            F Offline
                            freesun
                            wrote on last edited by
                            #13

                            yes excatly what you mentioned is what i wanto explain ..but this step will be the final step to obtain single value after integration y (in my case S) w.r.t x (in my case FF) and that value will be the P value which i want to get. But before following such approach i must get S values from that long, complex :( dS/dFF derivation..i have sent you equn i hope you will better understand.. angle phi (FF) in snapshot is defined as 0

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups