The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.
Good Afternoon Community,
Attached is a copy of Mathcad 15 file that I'm working on. I'm trying to convert a Matlab code into Mathcad file, I have done some work on the worksheet, but I ran into problem in converting Matlab programming into Mathcad programming. The Matlab code is at end of the worksheet. Would anybody please help me with the worksheet, my goal is to plot the time history of displacement, velocity and acceleration. Thank you in advance.
Boyer
Solved! Go to Solution.
Oh yes, you are right! That was pretty tricky with the brackets 😉
Now Mathcad delivers at least the correct results (unitless as in Matlab).
Hi Boyer,
as you see from the following picture, the variable p is undefined. Furthermore are missing some unit of measure.
Regards
FM
Good Evening F.M. Navigator,
Thank you for your help. I will look into the worksheet again and get back to you. Thanks again.
Boyer
Good Afternoon FM,
Please see a modified copy of the file you are helping on translation of Matlab file into Mathcad file. I have shown the p vector and changed the units as suggested by you. My Output is still not producing any result. Would be kind to see what I'm doing wrong.
Best Regards,
Boyer
Here is the solution worked from the matlab.
Matlab uses 1 as origin of vectors and matrices.
Mathcad uses 0 as origin of vectors or matrices by default.
You can set this with the ORIGIN worksheet variable in MathCad.
Keeping the one based arrays avoids all the variable-1 vector calls in programming.
poor variable choice in the matlab double v's as (vv) and w llok the same in MathCad
Hope the file helps. Cannot upload a MathCad14 file socan only send pdf
Cannot upload a MathCad14 file socan only send pdf
You have to put the file first in a zip or rar archive to be able to upload here.
BTW
Enclosed is working file.
With error spotted by werner corrected.
The equations are not unit consistent.
So you have to enter values in the right units without declaring units in mathcad. Only enter the values.
Terry
I guess your indices are inconsistent. You write u[i where in the Matlab file there is u(i-1) but you already corrected the different ORIGIN by looping from 1 to n and not from 2 to n1. You shouldn't "correct" it a second time.
Unfortunately this results in incredible high values. ??
@Boye
Can you confirm that the original Matlab file you included as two pictures ever worked OK?
Second Go with errors corrected gives reasonable looking graphs.
The equations are still not unit consistent so results should be used with caution
Hmmm, what did you change? (I'm too lazy to compare)
These were some of the indices I was talking about
They should all be i-1 as in the Matlab file. v[i for example is always 0 at the stage (in the Matlab file it even would not exist as vector v is not prefilled with zeros as you did).
The indices should be the very same as in the Matlab file as the ORIGIN shift from 1 to 0 is already considered by the limits of the for-loop.
When i=1 in your program we have to use v[0 as v[1 is not even defined yet (its 0 because you prallocated the whole vector)
I have my doubts as to the correctness of the Matlab file.
Good Afternoon Mathcad Community,
Please see attached the Matlab file I'm trying to convert into Mathcad with no luck.
Best Regards,
Boyer
Hi,
I've made some changes to make the program give you results. I am puzzled by "vel" value.
Good Morning Gentlemen,
I would like to thank all of you for helping me on the translation from Matlab into Mathcad. I really appreciate it very much, FM, Werner &Terry. Thanks again.
Best Regards,
Boyer
Hi,
Results should always be compared.
Here is another method for your single degree of freedom system.
Natural frequency used was obtained in a structural engineering suite.
Lots of pretty graphs
Hi,
Last posting.
Have shown how to handle units in stiffness calculations that are not unit consistent.
For instance a stiffness matrix for a simple beam element uses rotation z, deflections x and y. The stiffness matrix for the beam is thus unit inconsistent.
Use any units on input but divide by a consistent set of units for calculations. I use N,mm,tonne,s,N/mm,mm/s,mm/s^2, etc. so the value of gravity is 9806.65 mm/s^2 not 9.81 m/s^2. You see the difference in value used.
This means you could input in ft, m etc but still use consistent units in the calculations. A good example is length in m of colums but consistent units of mm needed. This means the difference of value of 5 compared to value of 5000.
I have assumed value in matlab programming part "k" and "ma" are actually stiffness and mass, but this is not clear in matlab sample.
Terry
This is the answer for deflection in some structural software I use.
Good Morning Terry,
Thanks for your help. The structural analysis package plot is the correct answer. Also my plot in Matlab confirm your structural package. I just do not know what I'm missing in the programming in Mathcad, that is not making the plot right. I tried to modify your Wilson file with units with no luck, see attached.
Best Regards,
Boyer
Can you please supply the full matlab *.m file rather than just the piece of it on the MathCad worksheet.
Zip the m.file and it should upload OK.
Hi,
I do not have a copy of matlab but use the freely available SciLab. It is easy to translate Matlab to Scilab.
In this instance just change the % comments to //. I get this in Scilab. Give me some time and I willl get this in MathCad.
>I do not have a copy of matlab but use the freely available SciLab.
Thats interesting! The result looks correct. I wonder why the values in my Mathcad sheet get that high!?
Good Evening Mathcad Community,
I would like to thank you all for your help. Terry, FM, Werner and the rest of the community. I want to convert the Matlab file into Mathcad because of the units in Mathcad. The file plot exactly as is shown on your page Terry. Thank all.
Boyer
Hi Boyer.
Glad you found what you were lokking for but I guess it would be fair to mark one of Terry's posts as solution. After all his input was by far more professional, he was trying to do the work using correct units (which was the reason you wanted it be done in Mathcad) and it was him who found the error in my unitless 1:1 translation from Matlab.
The attached seems to be a 1:1 translation of your Matlab program to Mathcad and sure gives not the desired results.
That was the reason for my questions if you are sure that the very sheet gave the desired results in Matlab.
Did you gave it a try in Matlab and can you provide a screenshot of the Matlab plots?
Hi,
Checking through this carefully. I know at least zz is calculated incorrectly in the MathCad sheet. Carefully following the brackets in the matlab file still doesn't fix the problem.
I do not have matlab but use scilab. Nearly the same thing and free. It gets a good plot but is still not the correct answer because of unit errors in the matlab and scilab files..
.
.
Oh yes, you are right! That was pretty tricky with the brackets 😉
Now Mathcad delivers at least the correct results (unitless as in Matlab).
This is correct the static deflection derived by 450000/k is 0.045 m so the graph of u looks correct
Yes. I just corrected the wrong formula for zz you pointed me to.
Guess I would't have found that error in a year 😉
Now its time for nicer varaible names, units and ORIGIN=0 and maybe turning the whole calculation into one function.
One last comment is appropriate.
The matlab and mathcad calculations are idealised for the calculation of stiffness.
In real life a secondary effect needs to be incorporated. In both columns a shift to the right of the girder at the top offsets a given distance horizontally from the support and causes additional moments in the columns and yet more horizontal deflection at the top. It is called P-delta effect or sidesway. This is not incorporated in the idealised calculations.
Hi Terry,
I really appreciate your effort in taking up the translation from Matlab into Mathcad with units and the discovery of the error in equation zz. I'm also a structural engineer.
Best Regards,
Boyer