Tests for physical dimension

Tests for physical dimension

by Martin Kraska -
Number of replies: 5
In a question I want to catch the error that a sysmbolic result(thus no units, just variables) is of wrong physical dimension.

The correct answer looks like this: 64/3*a^3*t with a and t being of dimension length. Thus I want to test the input for the degree in length dimension.

My first idea was to check if degree(ans,a)+degree(ans,t) = 4
but this fails with this answer:

256*a^2*t/(12*(a-t))

the test gives degree(ans,a)+degree(ans,t) =3. but clearly the expression is of degree 2 in length.

so the next try is to use

dimtest(f):= degree(ev(f,t=rand(1.0)*a),a);

which would fail if by chance a difference of t and a would be zero.

Thus I don't feel safe. Any general solution for checking physical dimensions of expressions?

Average of ratings: -
In reply to Martin Kraska

Re: Tests for physical dimension

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, so this is the moment I show how little physics I know... Anyway, what about something like replacing the variables with their dimensions, e.g.

ansdim1:ev(ans1,a=L,t=L);

Then decide if the degree of L is correct?

No, your second example gives a division by zero.  Sorry, we can't do this robustly currently I think.  An interesting project for a physics person: dimensional analysis in Maxima.

Average of ratings: Useful (1)
In reply to Christopher Sangwin

Re: Tests for physical dimension

by Martin Kraska -
One could try to use units of measurement mechanisms from Maxima or Stack. However, I am not familiar with them. When I tried to use them, it didn't work as expected.

Yet, it might be worth a second try, once our moodle and stack are updated.
In reply to Christopher Sangwin

Re: Tests for physical dimension

by Martin Kraska -
An option would be to do replace the variables by random multiples of the dimension, such that differences should not become actually zero. Then the dimensional test would be

substitutions: [var1=f1*unit1, var2=f2*unit2....];
numberp( ev(ans/tans, substitutions);

This isn't exactly safe but hopefully safe enough for practical application.
Average of ratings: Useful (1)
In reply to Martin Kraska

Re: Tests for physical dimension

by Leo Butler -
If the student's answer is ans1, and a and t are the variables both in units of length L, you are testing for homogeneity in L:

homog : rat( subst([a=L*a,t=L*t], ans1)/ans1/L^4 );

You then test if homog is 1. You can change that 4 to the desired/required degree.

Leo
In reply to Leo Butler

Re: Tests for physical dimension

by Martin Kraska -

This seems to be a very robust solution. The only drawback is that there must not be any overlap between variable and unit names (like m for mass and m for meter). Yet, this is easy to handle, as you either aren't going to expose the unit names in the feedback or you can use texput to substitute whatever you want for output.

I'll open an issue on github for further discussion.

Average of ratings: Useful (1)